From ccfdb3cf1251a4bffc9912ddf58cf798f39a079c Mon Sep 17 00:00:00 2001 From: ehmicky Date: Fri, 25 Sep 2020 17:05:10 +0200 Subject: [PATCH 1/2] Improve error handling of Rollup --- src/index.js | 20 +++++++++++-------- .../syntax-error/edge-handlers/example.js | 2 ++ test/fixtures/syntax-error/netlify.toml | 2 ++ test/main.js | 6 ++++++ 4 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 test/fixtures/syntax-error/edge-handlers/example.js create mode 100644 test/fixtures/syntax-error/netlify.toml diff --git a/src/index.js b/src/index.js index 53bbbd76..2b60dfa9 100644 --- a/src/index.js +++ b/src/index.js @@ -123,14 +123,18 @@ async function bundleFunctions(file, utils) { }, }; - const bundle = await rollup.rollup(options); - const { - output: [{ code }], - } = await bundle.generate({ - format: "iife", - compact: true, - }); - return code; + try { + const bundle = await rollup.rollup(options); + const { + output: [{ code }], + } = await bundle.generate({ + format: "iife", + compact: true, + }); + return code; + } catch (error) { + return utils.build.failBuild("Error while bundling Edge handlers", { error }); + } } /** diff --git a/test/fixtures/syntax-error/edge-handlers/example.js b/test/fixtures/syntax-error/edge-handlers/example.js new file mode 100644 index 00000000..961d761f --- /dev/null +++ b/test/fixtures/syntax-error/edge-handlers/example.js @@ -0,0 +1,2 @@ +// Intentional JavaScript error +exportt function onRequest() {} diff --git a/test/fixtures/syntax-error/netlify.toml b/test/fixtures/syntax-error/netlify.toml new file mode 100644 index 00000000..28d81494 --- /dev/null +++ b/test/fixtures/syntax-error/netlify.toml @@ -0,0 +1,2 @@ +[[plugins]] +package = "../../.." diff --git a/test/main.js b/test/main.js index beda9ca1..3749023a 100644 --- a/test/main.js +++ b/test/main.js @@ -8,6 +8,7 @@ const FIXTURES_DIR = `${__dirname}/fixtures`; const INTEGRATION_TEST_DIR = `${FIXTURES_DIR}/integration-test`; const CONFIG_FIXTURE_DIR = `${FIXTURES_DIR}/config-dir`; const WRONG_CONFIG_FIXTURE_DIR = `${FIXTURES_DIR}/wrong-config-dir`; +const SYNTAX_ERROR_FIXTURE_DIR = `${FIXTURES_DIR}/syntax-error`; test("Edge handlers should be bundled", async (t) => { await runNetlifyBuild(t, INTEGRATION_TEST_DIR); @@ -35,3 +36,8 @@ test("Edge handlers directory build.edge_handlers misconfiguration is reported", const { output } = await runNetlifyBuild(t, WRONG_CONFIG_FIXTURE_DIR, { expectedSuccess: false }); t.true(output.includes("does-not-exist")); }); + +test("Edge handlers directory build.edge_handlers syntax error is reported", async (t) => { + const { output } = await runNetlifyBuild(t, SYNTAX_ERROR_FIXTURE_DIR, { expectedSuccess: false }); + t.true(output.includes("Error while bundling")); +}); From 7bcf5b005e3cd0e8e9431d40a04b054f4fcf6302 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Fri, 25 Sep 2020 18:15:16 +0200 Subject: [PATCH 2/2] Add comment --- src/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.js b/src/index.js index 2b60dfa9..94b480ff 100644 --- a/src/index.js +++ b/src/index.js @@ -133,6 +133,8 @@ async function bundleFunctions(file, utils) { }); return code; } catch (error) { + // This will stop the execution of this plugin. + // No Edge handlers will be uploaded. return utils.build.failBuild("Error while bundling Edge handlers", { error }); } }