Skip to content
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

fix: check error type before modifying it #3385

Merged
merged 1 commit into from May 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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