| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,23 +34,23 @@ function collectFailed(task: Task, level: number): LeveledTask[] { | |||
| 34 | 34 | function createHtmlError(filter: Convert, error: ErrorWithDiff) { | |
| 35 | 35 | let htmlError = '' | |
| 36 | 36 | if (error.message?.includes('\x1B')) { | |
| 37 | - htmlError = `<b>${error.nameStr || error.name}</b>: ${filter.toHtml( | ||
| 37 | + htmlError = `<b>${error.name}</b>: ${filter.toHtml( | ||
| 38 | 38 | escapeHtml(error.message), | |
| 39 | 39 | )}` | |
| 40 | 40 | } | |
| 41 | 41 | ||
| 42 | - const startStrWithX1B = error.stackStr?.includes('\x1B') | ||
| 43 | - if (startStrWithX1B || error.stack?.includes('\x1B')) { | ||
| 42 | + const startStrWithX1B = error.stack?.includes('\x1B') | ||
| 43 | + if (startStrWithX1B) { | ||
| 44 | 44 | if (htmlError.length > 0) { | |
| 45 | 45 | htmlError += filter.toHtml( | |
| 46 | - escapeHtml((startStrWithX1B ? error.stackStr : error.stack) as string), | ||
| 46 | + escapeHtml((error.stack) as string), | ||
| 47 | 47 | ) | |
| 48 | 48 | } | |
| 49 | 49 | else { | |
| 50 | - htmlError = `<b>${error.nameStr || error.name}</b>: ${ | ||
| 50 | + htmlError = `<b>${error.name}</b>: ${ | ||
| 51 | 51 | error.message | |
| 52 | 52 | }${filter.toHtml( | |
| 53 | - escapeHtml((startStrWithX1B ? error.stackStr : error.stack) as string), | ||
| 53 | + escapeHtml((error.stack) as string), | ||
| 54 | 54 | )}` | |
| 55 | 55 | } | |
| 56 | 56 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,7 +44,7 @@ export function parseError(e: unknown) { | |||
| 44 | 44 | } | |
| 45 | 45 | } | |
| 46 | 46 | ||
| 47 | - error.stacks = parseStacktrace(error.stack || error.stackStr || '', { | ||
| 47 | + error.stacks = parseStacktrace(error.stack || '', { | ||
| 48 | 48 | ignoreStackEntries: [], | |
| 49 | 49 | }) | |
| 50 | 50 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,6 +32,25 @@ export function serializeValue(val: any, seen: WeakMap<WeakKey, any> = new WeakM | |||
| 32 | 32 | if (!val || typeof val === 'string') { | |
| 33 | 33 | return val | |
| 34 | 34 | } | |
| 35 | + if (val instanceof Error && 'toJSON' in val && typeof val.toJSON === 'function') { | ||
| 36 | + const jsonValue = val.toJSON() | ||
| 37 | + | ||
| 38 | + if (jsonValue && jsonValue !== val && typeof jsonValue === 'object') { | ||
| 39 | + if (typeof val.message === 'string') { | ||
| 40 | + safe(() => jsonValue.message ??= val.message) | ||
| 41 | + } | ||
| 42 | + if (typeof val.stack === 'string') { | ||
| 43 | + safe(() => jsonValue.stack ??= val.stack) | ||
| 44 | + } | ||
| 45 | + if (typeof val.name === 'string') { | ||
| 46 | + safe(() => jsonValue.name ??= val.name) | ||
| 47 | + } | ||
| 48 | + if (val.cause != null) { | ||
| 49 | + safe(() => jsonValue.cause ??= serializeValue(val.cause, seen)) | ||
| 50 | + } | ||
| 51 | + } | ||
| 52 | + return serializeValue(jsonValue, seen) | ||
| 53 | + } | ||
| 35 | 54 | if (typeof val === 'function') { | |
| 36 | 55 | return `Function<${val.name || 'anonymous'}>` | |
| 37 | 56 | } | |
@@ -106,6 +125,15 @@ export function serializeValue(val: any, seen: WeakMap<WeakKey, any> = new WeakM | |||
| 106 | 125 | } | |
| 107 | 126 | } | |
| 108 | 127 | ||
| 128 | + function safe(fn: () => void) { | ||
| 129 | + try { | ||
| 130 | + return fn() | ||
| 131 | + } | ||
| 132 | + catch { | ||
| 133 | + // ignore | ||
| 134 | + } | ||
| 135 | + } | ||
| 136 | + | ||
| 109 | 137 | export { serializeValue as serializeError } | |
| 110 | 138 | ||
| 111 | 139 | function normalizeErrorMessage(message: string) { | |
@@ -122,15 +150,6 @@ export function processError( | |||
| 122 | 150 | } | |
| 123 | 151 | const err = _err as TestError | |
| 124 | 152 | ||
| 125 | - // stack is not serialized in worker communication | ||
| 126 | - // we stringify it first | ||
| 127 | - if (typeof err.stack === 'string') { | ||
| 128 | - err.stackStr = String(err.stack) | ||
| 129 | - } | ||
| 130 | - if (typeof err.name === 'string') { | ||
| 131 | - err.nameStr = String(err.name) | ||
| 132 | - } | ||
| 133 | - | ||
| 134 | 153 | if ( | |
| 135 | 154 | err.showDiff | |
| 136 | 155 | || (err.showDiff === undefined | |
@@ -143,10 +162,10 @@ export function processError( | |||
| 143 | 162 | }) | |
| 144 | 163 | } | |
| 145 | 164 | ||
| 146 | - if (typeof err.expected !== 'string') { | ||
| 165 | + if ('expected' in err && typeof err.expected !== 'string') { | ||
| 147 | 166 | err.expected = stringify(err.expected, 10) | |
| 148 | 167 | } | |
| 149 | - if (typeof err.actual !== 'string') { | ||
| 168 | + if ('actual' in err && typeof err.actual !== 'string') { | ||
| 150 | 169 | err.actual = stringify(err.actual, 10) | |
| 151 | 170 | } | |
| 152 | 171 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -281,7 +281,7 @@ export function parseErrorStacktrace( | |||
| 281 | 281 | return e.stacks | |
| 282 | 282 | } | |
| 283 | 283 | ||
| 284 | - const stackStr = e.stack || e.stackStr || '' | ||
| 284 | + const stackStr = e.stack || '' | ||
| 285 | 285 | // if "stack" property was overwritten at runtime to be something else, | |
| 286 | 286 | // ignore the value because we don't know how to process it | |
| 287 | 287 | let stackFrames = typeof stackStr === 'string' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,9 +55,7 @@ export interface ErrorWithDiff { | |||
| 55 | 55 | message: string | |
| 56 | 56 | name?: string | |
| 57 | 57 | cause?: unknown | |
| 58 | - nameStr?: string | ||
| 59 | 58 | stack?: string | |
| 60 | - stackStr?: string | ||
| 61 | 59 | stacks?: ParsedStack[] | |
| 62 | 60 | showDiff?: boolean | |
| 63 | 61 | actual?: any | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -240,7 +240,7 @@ function printErrorInner( | |||
| 240 | 240 | }) | |
| 241 | 241 | } | |
| 242 | 242 | ||
| 243 | - handleImportOutsideModuleError(e.stack || e.stackStr || '', logger) | ||
| 243 | + handleImportOutsideModuleError(e.stack || '', logger) | ||
| 244 | 244 | ||
| 245 | 245 | return { nearest } | |
| 246 | 246 | } | |
@@ -250,10 +250,8 @@ function printErrorType(type: string, ctx: Vitest) { | |||
| 250 | 250 | } | |
| 251 | 251 | ||
| 252 | 252 | const skipErrorProperties = new Set([ | |
| 253 | - 'nameStr', | ||
| 254 | 253 | 'cause', | |
| 255 | 254 | 'stacks', | |
| 256 | - 'stackStr', | ||
| 257 | 255 | 'type', | |
| 258 | 256 | 'showDiff', | |
| 259 | 257 | 'ok', | |
@@ -274,6 +272,7 @@ const skipErrorProperties = new Set([ | |||
| 274 | 272 | 'VITEST_TEST_NAME', | |
| 275 | 273 | 'VITEST_TEST_PATH', | |
| 276 | 274 | 'VITEST_AFTER_ENV_TEARDOWN', | |
| 275 | + '__vitest_rollup_error__', | ||
| 277 | 276 | ...Object.getOwnPropertyNames(Error.prototype), | |
| 278 | 277 | ...Object.getOwnPropertyNames(Object.prototype), | |
| 279 | 278 | ]) | |
@@ -366,7 +365,7 @@ function printModuleWarningForSourceCode(logger: ErrorLogger, path: string) { | |||
| 366 | 365 | } | |
| 367 | 366 | ||
| 368 | 367 | function printErrorMessage(error: ErrorWithDiff, logger: ErrorLogger) { | |
| 369 | - const errorName = error.name || error.nameStr || 'Unknown Error' | ||
| 368 | + const errorName = error.name || 'Unknown Error' | ||
| 370 | 369 | if (!error.message) { | |
| 371 | 370 | logger.error(error) | |
| 372 | 371 | return | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -585,9 +585,9 @@ export abstract class BaseReporter implements Reporter { | |||
| 585 | 585 | task.result?.errors?.forEach((error) => { | |
| 586 | 586 | let previous | |
| 587 | 587 | ||
| 588 | - if (error?.stackStr) { | ||
| 588 | + if (error?.stack) { | ||
| 589 | 589 | previous = errorsQueue.find((i) => { | |
| 590 | - if (i[0]?.stackStr !== error.stackStr) { | ||
| 590 | + if (i[0]?.stack !== error.stack) { | ||
| 591 | 591 | return false | |
| 592 | 592 | } | |
| 593 | 593 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -250,7 +250,7 @@ export class JUnitReporter implements Reporter { | |||
| 250 | 250 | 'failure', | |
| 251 | 251 | { | |
| 252 | 252 | message: error?.message, | |
| 253 | - type: error?.name ?? error?.nameStr, | ||
| 253 | + type: error?.name, | ||
| 254 | 254 | }, | |
| 255 | 255 | async () => { | |
| 256 | 256 | if (!error) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,7 +41,7 @@ export class TapReporter implements Reporter { | |||
| 41 | 41 | } | |
| 42 | 42 | ||
| 43 | 43 | private logErrorDetails(error: ErrorWithDiff, stack?: ParsedStack) { | |
| 44 | - const errorName = error.name || error.nameStr || 'Unknown Error' | ||
| 44 | + const errorName = error.name || 'Unknown Error' | ||
| 45 | 45 | this.logger.log(`name: ${yamlString(String(errorName))}`) | |
| 46 | 46 | this.logger.log(`message: ${yamlString(String(error.message))}`) | |
| 47 | 47 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -244,11 +244,9 @@ export class Typechecker { | |||
| 244 | 244 | originalError: info, | |
| 245 | 245 | error: { | |
| 246 | 246 | name: error.name, | |
| 247 | - nameStr: String(error.name), | ||
| 248 | 247 | message: errMsg, | |
| 249 | 248 | stacks: error.stacks, | |
| 250 | 249 | stack: '', | |
| 251 | - stackStr: '', | ||
| 252 | 250 | }, | |
| 253 | 251 | } | |
| 254 | 252 | }) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments