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

Better error logging #1062

Merged
merged 8 commits into from Apr 17, 2021
Merged

Better error logging #1062

merged 8 commits into from Apr 17, 2021

Conversation

Rich-Harris
Copy link
Member

@Rich-Harris Rich-Harris commented Apr 17, 2021

This started out as a PR to address #982 specifically, but I ended up fixing a bunch of adjacent code:

  • the SSRRenderOptions type is much neater, with the options passed to app.render separated out
  • added SSRRenderState as distinct from SSRRenderOptions — this is used for tracking prerender dependencies and preventing infinite fetch loops. It means that the built app only needs to create the render options object once
  • exceptions are always console-logged, whether from endpoints or pages. This fixes More informative error messages in prerendering #982 without adding any additional machinery
  • error logging is more readable in dev
  • error responses (whether explicit or triggered by exceptions) in prerender will show which page linked to the erroring page, or which page fetched the erroring endpoint. This makes it much easier to find broken links etc

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpx changeset and following the prompts

@Rich-Harris Rich-Harris changed the title Gh 982 Better error logging Apr 17, 2021
* @param {string} path
* @param {string} parent
*/
async function visit(path, parent) {
Copy link
Member

Choose a reason for hiding this comment

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

parent_path might be a clearer name? Or could update the JSDoc to clarify that it's a path

Copy link
Member Author

Choose a reason for hiding this comment

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

I feel like it's obvious from usage. If you go by the name alone then you might think that the parent_path of /foo/bar was /foo, whereas if you scan down to where it's used, it becomes clear what it does

@benmccann
Copy link
Member

Cool!! I wonder if there are any tests we should add for this

@Rich-Harris
Copy link
Member Author

Cool!! I wonder if there are any tests we should add for this

Prerendering tests in general are a bit of a TODO

@Rich-Harris Rich-Harris merged commit 61d7fa0 into master Apr 17, 2021
@Rich-Harris Rich-Harris deleted the gh-982 branch April 17, 2021 14:40
@datio
Copy link

datio commented Jul 23, 2021

There's a regression when a unicode path is visit'ed because of the following change:

https://github.com/sveltejs/kit/blame/2a1e9795ad9773e04669a7b9d0234caa0b688ade/packages/kit/src/core/adapt/prerender.js#L227

If it's changed, say, to:

await visit(decodeURI(path), parsed.pathname.replace(config.kit.paths.base, ''));

It builds correctly.

@benmccann
Copy link
Member

@datio can you file a new issue instead of commenting on a closed PR? this will for sure get lost otherwise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More informative error messages in prerendering
3 participants