From 01c787a2264f477bef6487e21d7361a77cfd3dfe Mon Sep 17 00:00:00 2001 From: Florrie Date: Tue, 19 Sep 2017 17:08:59 -0300 Subject: Fix critical bug; http-music now halts if 5 tracks fail to download in a row --- src/loop-play.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/loop-play.js') 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." -- cgit 1.3.0-6-gf8a5