« get me outta code hell

Fix critical bug; http-music now halts if 5 tracks fail to download in a row - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2017-09-19 17:08:59 -0300
committerFlorrie <towerofnix@gmail.com>2017-09-19 17:08:59 -0300
commit01c787a2264f477bef6487e21d7361a77cfd3dfe (patch)
tree6262451515beb968ded690acda9a2c9aaa95e575 /src
parentfa41e5aae1c6874e730e6aff818f3ff57ba6d68e (diff)
Fix critical bug; http-music now halts if 5 tracks fail to download in a row
Diffstat (limited to 'src')
-rw-r--r--src/loop-play.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/loop-play.js b/src/loop-play.js
index d22833f..810d1c6 100644
--- a/src/loop-play.js
+++ b/src/loop-play.js
@@ -307,6 +307,7 @@ class PlayController extends EventEmitter {
     this.nextFile = undefined // TODO: Why isn't this null?
     this.stopped = false
     this.shouldMoveNext = true
+    this.failedCount = 0
   }
 
   async loopPlay() {
@@ -401,6 +402,7 @@ class PlayController extends EventEmitter {
       .then(file => {
         this.isDownloading = false
         this.nextFile = file
+        this.failedCount = 0
         this.emit('downloaded')
       })
       .catch(err => {
@@ -411,6 +413,18 @@ class PlayController extends EventEmitter {
         )
         console.warn(err)
 
+        this.failedCount++
+
+        if (this.failedCount >= 5) {
+          console.error(
+            "\x1b[31mFailed to download 5 tracks in a row. Halting, to " +
+            "prevent damage to the computer.\x1b[0m"
+          )
+
+          process.exit(0)
+          throw new Error('Intentionally halted.')
+        }
+
         // A little bit blecht, but.. this works.
         // "When a track fails, remove it from the timeline, and start
         // downloading whatever track fills its place."