From ed48599aa972ea4b822353c47b614f67a019bd56 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 11 Sep 2018 15:18:32 -0500 Subject: [PATCH 1/5] downloadFile should callback w/ err msg if response code is not 200 --- lib/utils/utils.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/utils/utils.js b/lib/utils/utils.js index 7ccbc620..e32cd2f5 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -160,6 +160,9 @@ function downloadFile(url, dest, cb) { const o_fs = require('fs-extra'); var file = o_fs.createWriteStream(dest); (url.substring(0, 5) === 'https' ? https : http).get(url, function (response) { + if (response.statusCode !== 200) { + if (cb) cb(`Download failed, response code ${response.statusCode}`); + } response.pipe(file); file.on('finish', function () { file.close(cb); From a44be3740bc7979e77467a9065201d27747880c0 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 11 Sep 2018 15:19:15 -0500 Subject: [PATCH 2/5] template generator should report err msg and exit if download fails --- lib/utils/template_generator.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/utils/template_generator.js b/lib/utils/template_generator.js index 259144af..0ed45925 100644 --- a/lib/utils/template_generator.js +++ b/lib/utils/template_generator.js @@ -22,7 +22,11 @@ class TemplateGenerator { console.log(__('Installing Template from ' + uri + '....').green); fs.mkdirpSync(utils.dirname(tmpFilePath)); - utils.downloadFile(url, tmpFilePath, () => { + utils.downloadFile(url, tmpFilePath, (err) => { + if (err) { + console.error(err.red); + process.exit(1); + } utils.extractZip(tmpFilePath, fspath, { map: file => { let fixed_path = file.path.split('/'); From 803b3f505061b7326b390f9be6a7afb7aa6f2710 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 11 Sep 2018 15:22:35 -0500 Subject: [PATCH 3/5] should return after callback w/ error --- lib/utils/utils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/utils/utils.js b/lib/utils/utils.js index e32cd2f5..4c0bfe77 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -162,6 +162,7 @@ function downloadFile(url, dest, cb) { (url.substring(0, 5) === 'https' ? https : http).get(url, function (response) { if (response.statusCode !== 200) { if (cb) cb(`Download failed, response code ${response.statusCode}`); + return; } response.pipe(file); file.on('finish', function () { From a4af0d8f5b820d36b95aeb5236d981a60f6fced6 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 11 Sep 2018 15:44:37 -0500 Subject: [PATCH 4/5] assume cb is always supplied --- lib/utils/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/utils/utils.js b/lib/utils/utils.js index 4c0bfe77..acc2ade9 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -161,7 +161,7 @@ function downloadFile(url, dest, cb) { var file = o_fs.createWriteStream(dest); (url.substring(0, 5) === 'https' ? https : http).get(url, function (response) { if (response.statusCode !== 200) { - if (cb) cb(`Download failed, response code ${response.statusCode}`); + cb(`Download failed, response code ${response.statusCode}`); return; } response.pipe(file); @@ -170,7 +170,7 @@ function downloadFile(url, dest, cb) { }); }).on('error', function (err) { o_fs.unlink(dest); - if (cb) cb(err.message); + cb(err.message); }); } From a9865eedc532d686160fc1339cb889ffcbb95a66 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 11 Sep 2018 15:44:54 -0500 Subject: [PATCH 5/5] provide helpful messages when template download fails --- lib/utils/template_generator.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/utils/template_generator.js b/lib/utils/template_generator.js index 0ed45925..1693bb49 100644 --- a/lib/utils/template_generator.js +++ b/lib/utils/template_generator.js @@ -25,6 +25,8 @@ class TemplateGenerator { utils.downloadFile(url, tmpFilePath, (err) => { if (err) { console.error(err.red); + console.error('Does the template really exist?'.red); + console.error(`Embark's supported templates: https://embark.status.im/templates/`.green); process.exit(1); } utils.extractZip(tmpFilePath, fspath, {