From ac4c5b7d27c31f15fcfe7aa38c7d4201f9220bd1 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Fri, 1 Nov 2019 16:27:21 -0600 Subject: [PATCH] preserve stack from got (HTTP client) error when downloading UI --- CHANGELOG.adoc | 6 ++++++ packages/ui-loader/lib/load-ui.js | 4 +++- packages/ui-loader/test/load-ui-test.js | 12 ++++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 843e5a519..1f014854e 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -5,6 +5,12 @@ For a detailed view of what's changed, refer to the repository's https://gitlab. This project utilizes semantic versioning. +== Unreleased + +=== Changed + +* *ui-loader*: Preserve stack from got (HTTP client) error when downloading UI (#516) + == 2.2.0 (2019-11-02) === Added diff --git a/packages/ui-loader/lib/load-ui.js b/packages/ui-loader/lib/load-ui.js index 4aadd3559..5ae10359f 100644 --- a/packages/ui-loader/lib/load-ui.js +++ b/packages/ui-loader/lib/load-ui.js @@ -130,7 +130,9 @@ function downloadBundle (url, to) { return get(url, { encoding: null }) .then(({ body }) => fs.outputFile(to, body).then(() => to)) .catch((e) => { - throw new Error(`Failed to download UI bundle: ${url}\nreason: ${e.message}`) + const wrapped = new Error(`Failed to download UI bundle: ${url}`) + wrapped.stack += '\nCaused by: ' + (e.stack || 'unknown') + throw wrapped }) } diff --git a/packages/ui-loader/test/load-ui-test.js b/packages/ui-loader/test/load-ui-test.js index ac5a2952b..c6661d6f8 100644 --- a/packages/ui-loader/test/load-ui-test.js +++ b/packages/ui-loader/test/load-ui-test.js @@ -85,8 +85,16 @@ describe('loadUi()', () => { describe('should throw error if bundle cannot be found', () => { testAll('no-such-bundle.zip', async (playbook) => { const loadUiDeferred = await deferExceptions(loadUi, playbook) - const expectedMessage = playbook.ui.bundle.url.startsWith('http://') ? '404' : 'does not exist' - expect(loadUiDeferred).to.throw(expectedMessage) + if (playbook.ui.bundle.url.startsWith('http://')) { + const expectedMessage = `Failed to download UI bundle: ${playbook.ui.bundle.url}` + expect(loadUiDeferred) + .to.throw(expectedMessage) + .with.property('stack') + .that.matches(/Caused by: HTTP.*404/) + } else { + const expectedMessage = `UI bundle does not exist: ${playbook.ui.bundle.url}` + expect(loadUiDeferred).to.throw(expectedMessage) + } }) }) -- GitLab