Skip to content

Commit

Permalink
fix: display pre-transform error details (#18764)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Nov 26, 2024
1 parent db697ef commit 554f45f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
12 changes: 8 additions & 4 deletions packages/vite/src/node/server/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
} from './pluginContainer'
import { type WebSocketServer, isWebSocketServer } from './ws'
import { warmupFiles } from './warmup'
import { buildErrorMessage } from './middlewares/error'

export interface DevEnvironmentContext {
hot: boolean
Expand Down Expand Up @@ -220,10 +221,13 @@ export class DevEnvironment extends BaseEnvironment {
return
}
// Unexpected error, log the issue but avoid an unhandled exception
this.logger.error(`Pre-transform error: ${e.message}`, {
error: e,
timestamp: true,
})
this.logger.error(
buildErrorMessage(e, [`Pre-transform error: ${e.message}`], false),
{
error: e,
timestamp: true,
},
)
}
}

Expand Down
13 changes: 8 additions & 5 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import { timeMiddleware } from './middlewares/time'
import { ModuleGraph } from './mixedModuleGraph'
import type { ModuleNode } from './mixedModuleGraph'
import { notFoundMiddleware } from './middlewares/notFound'
import { errorMiddleware } from './middlewares/error'
import { buildErrorMessage, errorMiddleware } from './middlewares/error'
import type { HmrOptions, HotBroadcaster } from './hmr'
import {
createDeprecatedHotBroadcaster,
Expand Down Expand Up @@ -569,10 +569,13 @@ export async function _createServer(
return
}
// Unexpected error, log the issue but avoid an unhandled exception
server.config.logger.error(`Pre-transform error: ${e.message}`, {
error: e,
timestamp: true,
})
server.config.logger.error(
buildErrorMessage(e, [`Pre-transform error: ${e.message}`], false),
{
error: e,
timestamp: true,
},
)
}
},
transformIndexHtml(url, html, originalUrl) {
Expand Down

0 comments on commit 554f45f

Please sign in to comment.