Skip to content

Commit

Permalink
fix(error-handling): avoid serilaizing unnecessary error properties w…
Browse files Browse the repository at this point in the history
…hen seinding to client

fix #1373
  • Loading branch information
yyx990803 committed Jan 5, 2021
1 parent 1046fe0 commit 61aec65
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/vite/src/node/server/middlewares/error.ts
Expand Up @@ -4,13 +4,19 @@ import { ViteDevServer } from '../..'
import { Connect } from 'types/connect'
import { pad } from '../../utils'
import strip from 'strip-ansi'
import { ErrorPayload } from 'types/hmrPayload'

export function prepareError(err: Error | RollupError) {
export function prepareError(err: Error | RollupError): ErrorPayload['err'] {
// only copy the information we need and avoid serializing unnecessary
// properties, since some errors may attach full objects (e.g. PostCSS)
return {
...err,
message: strip(err.message),
stack: strip(err.stack || ''),
frame: strip((err as RollupError).frame || '')
id: (err as RollupError).id,
frame: strip((err as RollupError).frame || ''),
plugin: (err as RollupError).plugin,
pluginCode: (err as RollupError).pluginCode,
loc: (err as RollupError).loc
}
}

Expand Down

0 comments on commit 61aec65

Please sign in to comment.