-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
fix(dev): only rewrite SSR stacktrace when possible #4248
Conversation
}) | ||
} else if (writable) { | ||
e.stack = stacktrace | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we warn if neither configurable nor writable, so the dependency gets fixed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, emitting the warning properly would require server
instance, which wouldn't be accessible inside rebindErrorStacktrace
. Would it be better to:
Pass in a server instance to have rebindErrorStacktrace
emit the warning?
function rebindErrorStacktrace(e: Error, stacktrace: string, server: ViteDevServer): void
Return a boolean for success and have the respective consumers emit the warning? There probably would also be more context available for more detailed errors.
function rebindErrorStacktrace(e: Error, stacktrace: string): boolean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking we should deprecate ssrRewriteStacktrace
in favor of a SSRError extends Error
subclass whose constructor takes a stack trace string. So for now, I vote to merge this PR as-is.
Current Behavior
vite/packages/vite/src/node/server/index.ts
Lines 367 to 371 in 772b2f7
vite/packages/vite/src/node/ssr/ssrModuleLoader.ts
Lines 144 to 146 in 772b2f7
Currently, Vite assumes that the
stack
property of an error will always be writable. Unfortunately, this is not always the case, as seen here in thediscord-oauth2
module:This leads to errors inside
ssrFixStacktrace
:Proposed Behavior
configurable
(i.e. redefinable withObject.defineProperty
). If so, redefine the property.writable
. If so, perform assignment to the property.As
ssrFixStacktrace
is an in-place operation, we cannot return a new error object with the redefined stack-trace. I am unsure if there's a better way to handle this.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).