MCPcopy
hub / github.com/vitest-dev/vitest / processError

Function processError

packages/utils/src/error.ts:9–60  ·  view source on GitHub ↗
(
  _err: any,
  diffOptions?: DiffOptions,
  seen: WeakSet<WeakKey> = new WeakSet(),
)

Source from the content-addressed store, hash-verified

7export { serializeValue as serializeError }
8
9export function processError(
10 _err: any,
11 diffOptions?: DiffOptions,
12 seen: WeakSet<WeakKey> = new WeakSet(),
13): TestError {
14 if (!_err || typeof _err !== 'object') {
15 return { message: String(_err) }
16 }
17 const err = _err as TestError
18
19 if (
20 err.showDiff
21 || (err.showDiff === undefined
22 && err.expected !== undefined
23 && err.actual !== undefined)
24 ) {
25 const options = {
26 ...diffOptions,
27 ...err.diffOptions as DiffOptions,
28 }
29 err.diff = printDiffOrStringify(
30 err.actual,
31 err.expected,
32 options,
33 err,
34 )
35
36 err.expected = prettifyValue(err.expected, options)
37 err.actual = prettifyValue(err.actual, options)
38 }
39
40 // some Error implementations may not allow rewriting cause
41 // in most cases, the assignment will lead to "err.cause = err.cause"
42 try {
43 if (!seen.has(err) && typeof err.cause === 'object') {
44 seen.add(err)
45 err.cause = processError(err.cause, diffOptions, seen)
46 }
47 }
48 catch {}
49
50 try {
51 return serializeValue(err)
52 }
53 catch (e: any) {
54 return serializeValue(
55 new Error(
56 `Failed to fully serialize error: ${e?.message}\nInner error message: ${err?.message}`,
57 ),
58 )
59 }
60}
61
62function prettifyValue(value: unknown, options: DiffOptions): string | undefined {
63 if (typeof value !== 'string') {

Callers 15

collectTestsFunction · 0.90
runTestFunction · 0.90
failTaskFunction · 0.90
runSuiteFunction · 0.90
runFilesFunction · 0.90
interpretTaskModesFunction · 0.90
checkAllowOnlyFunction · 0.90
handleTestErrorFunction · 0.90
onAfterRunSuiteMethod · 0.90
error.test.tsFile · 0.90
getErrorDiffFunction · 0.90
expect.test.tsFile · 0.90

Calls 5

printDiffOrStringifyFunction · 0.90
serializeValueFunction · 0.90
prettifyValueFunction · 0.85
hasMethod · 0.45
addMethod · 0.45

Tested by 3

getErrorDiffFunction · 0.72
getErrorFunction · 0.72
snapshotErrorFunction · 0.72