From ae2f4a8caacfb671db159f3cdce0894beb485b4f Mon Sep 17 00:00:00 2001 From: "S. Elliott Johnson" Date: Mon, 17 Apr 2023 11:47:25 -0600 Subject: [PATCH] feat: improve error message for `handleHttpError` and `handleMissingId` (#9621) * patch: Improve error message for `handleHttpError` and `handleMissingId` * chore: changest * Update .changeset/tall-bags-sparkle.md * put the message in the fallback handler * oops --------- Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> Co-authored-by: Rich Harris --- .changeset/tall-bags-sparkle.md | 5 +++ packages/kit/src/core/config/index.spec.js | 2 -- packages/kit/src/core/config/options.js | 36 ++++++++++++++++------ 3 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 .changeset/tall-bags-sparkle.md diff --git a/.changeset/tall-bags-sparkle.md b/.changeset/tall-bags-sparkle.md new file mode 100644 index 000000000000..1b66de3f7e35 --- /dev/null +++ b/.changeset/tall-bags-sparkle.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: better error messages for handleable prerender failures diff --git a/packages/kit/src/core/config/index.spec.js b/packages/kit/src/core/config/index.spec.js index 78142e7623b0..56e42a55ab4b 100644 --- a/packages/kit/src/core/config/index.spec.js +++ b/packages/kit/src/core/config/index.spec.js @@ -105,8 +105,6 @@ const get_defaults = (prefix = '') => ({ concurrency: 1, crawl: true, entries: ['*'], - handleHttpError: 'fail', - handleMissingId: 'fail', origin: 'http://sveltekit-prerender' }, version: { diff --git a/packages/kit/src/core/config/options.js b/packages/kit/src/core/config/options.js index cdaf2d3be02c..b1b63d3a3154 100644 --- a/packages/kit/src/core/config/options.js +++ b/packages/kit/src/core/config/options.js @@ -201,17 +201,33 @@ const options = object( return input; }), - handleHttpError: validate('fail', (input, keypath) => { - if (typeof input === 'function') return input; - if (['fail', 'warn', 'ignore'].includes(input)) return input; - throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`); - }), + handleHttpError: validate( + (/** @type {any} */ { message }) => { + throw new Error( + message + + `\nTo suppress or handle this error, implement \`handleHttpError\` in https://kit.svelte.dev/docs/configuration#prerender` + ); + }, + (input, keypath) => { + if (typeof input === 'function') return input; + if (['fail', 'warn', 'ignore'].includes(input)) return input; + throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`); + } + ), - handleMissingId: validate('fail', (input, keypath) => { - if (typeof input === 'function') return input; - if (['fail', 'warn', 'ignore'].includes(input)) return input; - throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`); - }), + handleMissingId: validate( + (/** @type {any} */ { message }) => { + throw new Error( + message + + `\nTo suppress or handle this error, implement \`handleMissingId\` in https://kit.svelte.dev/docs/configuration#prerender` + ); + }, + (input, keypath) => { + if (typeof input === 'function') return input; + if (['fail', 'warn', 'ignore'].includes(input)) return input; + throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`); + } + ), origin: validate('http://sveltekit-prerender', (input, keypath) => { assert_string(input, keypath);