Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve error message for handleHttpError and handleMissingId #9621

Merged
merged 5 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tall-bags-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: better error messages for handleable prerender failures
8 changes: 6 additions & 2 deletions packages/kit/src/core/postbuild/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ async function prerender({ out, manifest_path, metadata, verbose, env }) {
? `${path} does not begin with \`base\`, which is configured in \`paths.base\` and can be imported from \`$app/paths\` - see https://kit.svelte.dev/docs/configuration#paths for more info`
: path;

return `${status} ${message}${referrer ? ` (${referenceType} from ${referrer})` : ''}`;
return (
`${status} ${message}${referrer ? ` (${referenceType} from ${referrer})` : ''}` +
`\nTo suppress or handle this error, implement \`handleHttpError\` in https://kit.svelte.dev/docs/configuration#prerender`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that if the user implements handleHttpError this will be the message passed to that function and it might be undesirable to include "To suppress or handle this error..." there as you'll be getting that message even when you do implement the function

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well now we're full-circle, ha -- what's the solution to the issue if not this?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, looking at the signature for the handler, I'm not sure this message would be undesirable -- we pass through the parsed information they need to do actual handling, so hopefully they're not trying to parse the message or something silly like that...

Copy link
Member

@dummdidumm dummdidumm Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to agree with @tcc-sejohnson - the message is desirable IMO (won't merge for now to let others weigh in)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ben's right, it's weird for this text to show up if the handler was implemented. Whether or not it's likely that someone will use message in their own handlers is separate to the question of whether the message is correct (but the whole reason it's provided is so that you can use it)

);
}
);

Expand All @@ -122,7 +125,8 @@ async function prerender({ out, manifest_path, metadata, verbose, env }) {
({ path, id, referrers }) => {
return (
`The following pages contain links to ${path}#${id}, but no element with id="${id}" exists on ${path} - see the \`handleMissingId\` option in https://kit.svelte.dev/docs/configuration#prerender for more info:` +
referrers.map((l) => `\n - ${l}`).join('')
referrers.map((l) => `\n - ${l}`).join('') +
`\nTo suppress or handle this error, implement \`handleMissingId\` in https://kit.svelte.dev/docs/configuration#prerender`
);
}
);
Expand Down