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);