Skip to content

Commit c44d991

Browse files
authored
fix: check error type before modifying it (#3385)
1 parent 324a9b5 commit c44d991

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/vitest/src/node/state.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { relative } from 'pathe'
2-
import type { ErrorWithDiff, File, Task, TaskResultPack, UserConsoleLog } from '../types'
2+
import type { File, Task, TaskResultPack, UserConsoleLog } from '../types'
33

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

3131
catchError(err: unknown, type: string): void {
3232
if (isAggregateError(err))
33-
return err.errors.forEach(error => this.catchError(error, type));
33+
return err.errors.forEach(error => this.catchError(error, type))
34+
35+
if (err === Object(err))
36+
(err as Record<string, unknown>).type = type
37+
else
38+
err = { type, message: err }
3439

35-
(err as ErrorWithDiff).type = type
3640
this.errorsSet.add(err)
3741
}
3842

0 commit comments

Comments
 (0)