From 36eabda506812428acc1d23228459fc3a99aaaf3 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 25 Sep 2018 09:20:59 -0500 Subject: [PATCH] rev error handling so error msg from hosted-git-info would be logged --- lib/utils/template_generator.js | 30 ++++++++++++++++-------------- test/template.js | 10 ++++++++++ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/lib/utils/template_generator.js b/lib/utils/template_generator.js index 1598a2d2e..60db9ae12 100644 --- a/lib/utils/template_generator.js +++ b/lib/utils/template_generator.js @@ -18,7 +18,14 @@ class TemplateGenerator { const fspath = utils.joinPath(destinationFolder, name); this.checkPathExists(fspath); const self = this; - let {url, filePath, browse} = this.getExternalProject(uri); + let ext; + try { + ext = this.getExternalProject(uri); + } catch (e) { + console.error(utils.errorMessage(e).red); + process.exit(1); + } + let {url, filePath, browse} = ext; let tmpFilePath = fs.tmpDir(filePath); console.log(__('Installing template from ' + browse).green); console.log(__('Downloading template...').green); @@ -91,20 +98,15 @@ class TemplateGenerator { getExternalProject(uri) { let url, folder, hgi; - try { - hgi = hostedGitInfo.fromUrl(uri); - if (!hgi || hgi.user.includes('#')) { - let templateAndBranch = uri.split('#'); - templateAndBranch[0] = `embark-framework/embark-${templateAndBranch[0]}-template`; - hgi = hostedGitInfo.fromUrl(templateAndBranch.join('#')); - } - if(!hgi) { throw new Error(); } - url = hgi.tarball(); - folder = `${hgi.user}/${hgi.project}/${hgi.committish || 'master'}`; - } catch (e) { - console.error('Unsupported template name or git host URL'.red); - process.exit(1); + hgi = hostedGitInfo.fromUrl(uri); + if (!hgi || hgi.user.includes('#')) { + let templateAndBranch = uri.split('#'); + templateAndBranch[0] = `embark-framework/embark-${templateAndBranch[0]}-template`; + hgi = hostedGitInfo.fromUrl(templateAndBranch.join('#')); } + if(!hgi) { throw new Error('Unsupported template name or git host URL'); } + url = hgi.tarball(); + folder = `${hgi.user}/${hgi.project}/${hgi.committish || 'master'}`; return { url, diff --git a/test/template.js b/test/template.js index a38c69d0d..aee28cc64 100644 --- a/test/template.js +++ b/test/template.js @@ -112,5 +112,15 @@ describe('TemplateGenerator', function () { }); + describe('with unsupported template specifier', function () { + + it('raises an exception', function () { + assert.throws(() => templateGenerator.getExternalProject("bad://format"), /Unsupported/); + assert.throws(() => templateGenerator.getExternalProject("bad://format#/also/bad"), /Unsupported/); + assert.throws(() => templateGenerator.getExternalProject(/force an error/), Error); + }); + + }); + }); });