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

Expose ssrRewriteStacktrace #7045

Closed
4 tasks done
Rich-Harris opened this issue Feb 22, 2022 · 0 comments · Fixed by #7091
Closed
4 tasks done

Expose ssrRewriteStacktrace #7045

Rich-Harris opened this issue Feb 22, 2022 · 0 comments · Fixed by #7091
Labels
enhancement: pending triage feat: ssr p2-nice-to-have Not breaking anything but nice to have (priority)

Comments

@Rich-Harris
Copy link
Contributor

Clear and concise description of the problem

In SvelteKit, stack traces are rendered in dev mode on error pages for errors encountered during SSR. These errors could be expected...

export function load() {
  return {
    status: 400,
    error: new Error('This error was expected')
  };
}

...or unexpected:

export function load() {
  throw new Error('This error was unexpected');
}

In the latter case, the error is also logged, before the error page is rendered. This means that we end up calling ssrFixStacktrace twice — once when it's logged, and again when it's rendered. But since ssrFixStacktrace isn't idempotent, the second call should really be called ssrBreakStacktrace.

Suggested solution

We can work around it, allowing us to fix stack traces at render time regardless of whether they were already fixed for logging...

function fix_stack_trace(error) {
  const original = error.stack;
  vite.ssrFixStacktrace(error);
  const fixed = error.stack;
  error.stack = original;

  return fixed;
}

...but it would be neater if instead Vite exposed the internal ssrRewriteStacktrace helper, so that we weren't mutating error objects in the first place.

Alternative

No response

Additional context

No response

Validations

@Niputi Niputi added feat: ssr p2-nice-to-have Not breaking anything but nice to have (priority) labels Feb 22, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Mar 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: pending triage feat: ssr p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants