Skip to content

feat: hide error stack unless VITE_BACKTRACE is set #20104

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@
],
"onlyBuiltDependencies": [
"@parcel/watcher",
"@tailwindcss/oxide",
"bcrypt",
"esbuild",
"playwright-chromium",
"rolldown",
"simple-git-hooks",
"unrs-resolver",
"workerd"
]
},
Expand Down
17 changes: 12 additions & 5 deletions packages/vite/src/node/server/middlewares/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,16 @@ function cleanStack(stack: string) {
.join('\n')
}

export function logError(server: ViteDevServer, err: RollupError): void {
const msg = buildErrorMessage(err, [
colors.red(`Internal server error: ${err.message}`),
])
export function logError(
server: ViteDevServer,
err: RollupError,
stack: boolean,
): void {
const msg = buildErrorMessage(
err,
[colors.red(`Internal server error: ${err.message}`)],
stack,
)

server.config.logger.error(msg, {
clear: true,
Expand All @@ -66,7 +72,8 @@ export function errorMiddleware(
// note the 4 args must be kept for connect to treat this as error middleware
// Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
return function viteErrorMiddleware(err: RollupError, _req, res, next) {
logError(server, err)
const printStack = process.env.VITE_BACKTRACE
logError(server, err, printStack === undefined || printStack !== '0')

if (allowNext) {
next()
Expand Down