« get me outta code hell

Misc. error messages in crawlers - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-07-03 01:15:51 -0300
committerFlorrie <towerofnix@gmail.com>2018-07-03 01:15:51 -0300
commit8c31848f4bbe0957b4d7a2c0522df09d7f1c6bc5 (patch)
treefb711f881f8408a90ca19dbce2a8f8ddbbcf9c3d
parent35d24ba00a4885ac086c61412ea6e084a0fa0afa (diff)
Misc. error messages in crawlers
-rw-r--r--crawlers.js27
1 files changed, 22 insertions, 5 deletions
diff --git a/crawlers.js b/crawlers.js
index 1db02fd..daf8221 100644
--- a/crawlers.js
+++ b/crawlers.js
@@ -231,7 +231,7 @@ function crawlLocal(dirPath, extensions = [
   'ogg', 'oga',
   'wav', 'mp3', 'mp4', 'm4a', 'aac',
   'mod'
-]) {
+], isTop = true) {
   // If the passed path is a file:// URL, try to decode it:
   try {
     const url = new URL(dirPath)
@@ -252,7 +252,7 @@ function crawlLocal(dirPath, extensions = [
 
       return stat(itemPath).then(stats => {
         if (stats.isDirectory()) {
-          return crawlLocal(itemPath, extensions)
+          return crawlLocal(itemPath, extensions, false)
             .then(group => Object.assign({name: item}, group))
         } else if (stats.isFile()) {
           // Extname returns a string starting with a dot; we don't want the
@@ -271,11 +271,23 @@ function crawlLocal(dirPath, extensions = [
             return null
           }
         }
-      })
+      }, statErr => null)
     }))
   }, err => {
     if (err.code === 'ENOENT') {
-      return []
+      if (isTop) {
+        throw 'That directory path does not exist!'
+      } else {
+        return []
+      }
+    } else if (err.code === 'EACCES') {
+      if (isTop) {
+        throw 'You do not have permission to open that directory.'
+      } else {
+        return []
+      }
+    } else {
+      throw err
     }
   }).then(items => items.filter(Boolean))
     .then(filteredItems => ({items: filteredItems}))
@@ -319,7 +331,12 @@ async function crawlYouTube(url) {
   })
 
   // Pass false so it doesn't show logging.
-  await promisifyProcess(ytdl, false)
+  try {
+    await promisifyProcess(ytdl, false)
+  } catch (error) {
+    // Yeow.
+    throw 'Youtube-dl failed.'
+  }
 
   return {
     items: items.map(item => {