Skip to content

Commit

Permalink
fix: check error type before modifying it (#3385)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed May 17, 2023
1 parent 324a9b5 commit c44d991
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/vitest/src/node/state.ts
@@ -1,5 +1,5 @@
import { relative } from 'pathe'
import type { ErrorWithDiff, File, Task, TaskResultPack, UserConsoleLog } from '../types'
import type { File, Task, TaskResultPack, UserConsoleLog } from '../types'

// can't import actual functions from utils, because it's incompatible with @vitest/browsers
import type { AggregateError as AggregateErrorPonyfill } from '../utils'
Expand Down Expand Up @@ -30,9 +30,13 @@ export class StateManager {

catchError(err: unknown, type: string): void {
if (isAggregateError(err))
return err.errors.forEach(error => this.catchError(error, type));
return err.errors.forEach(error => this.catchError(error, type))

if (err === Object(err))
(err as Record<string, unknown>).type = type
else
err = { type, message: err }

(err as ErrorWithDiff).type = type
this.errorsSet.add(err)
}

Expand Down

0 comments on commit c44d991

Please sign in to comment.