{"record":{"id":"ba12c90670e0dc47","repo":"vitest-dev/vitest","slug":"error-message","errorCode":null,"errorMessage":"error.message","messagePattern":"error\\.message","errorType":"exception","errorClass":"PrettyFormatPluginError","httpStatus":null,"severity":"error","filePath":"packages/pretty-format/src/index.ts","lineNumber":355,"sourceCode":"          val,\n          valChild => printer(valChild, config, indentation, depth, refs),\n          (str) => {\n            const indentationNext = indentation + config.indent\n            return (\n              indentationNext\n              + str.replaceAll(NEWLINE_REGEXP, `\\n${indentationNext}`)\n            )\n          },\n          {\n            edgeSpacing: config.spacingOuter,\n            min: config.min,\n            spacing: config.spacingInner,\n          },\n          config.colors,\n        )\n  }\n  catch (error: any) {\n    throw new PrettyFormatPluginError(error.message, error.stack)\n  }\n  if (typeof printed !== 'string') {\n    throw new TypeError(\n      `pretty-format: Plugin must return type \"string\" but instead returned \"${typeof printed}\".`,\n    )\n  }\n  return printed\n}\n\nfunction findPlugin(plugins: Plugins, val: unknown) {\n  for (const plugin of plugins) {\n    try {\n      if (plugin.test(val)) {\n        return plugin\n      }\n    }\n    catch (error: any) {\n      throw new PrettyFormatPluginError(error.message, error.stack)","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/pretty-format/src/index.ts#L337-L373","documentation":"A pretty-format plugin's serialize or print method threw an error during formatting; the catch wraps it into a PrettyFormatPluginError using error.message. This is a re-thrown plugin failure, not a pretty-format bug — the underlying message comes from inside the plugin that was selected to format the value.","triggerScenarios":"Any registered pretty-format plugin throwing while serializing a value (e.g. React/DOM/Immutable plugin encountering an unexpected shape, a plugin accessing a property that does not exist, circular refs mishandled).","commonSituations":"Custom plugin that throws on edge-case values; a third-party plugin incompatible with the value type; pretty-format invoked on an object whose getter throws; version skew between plugin and pretty-format.","solutions":[],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  format(value, { plugins })\n} catch (e) {\n  if (e instanceof PrettyFormatPluginError) {\n    // inspect original plugin error via e.stack; disable/fallback plugin\n    format(value, { plugins: plugins.filter(p => p !== suspect) })\n  } else throw e\n}","preventionTips":["Keep custom plugins defensive (try/catch internally)","Pin plugin versions compatible with pretty-format","Test plugins against the value shapes they will encounter"],"tags":["pretty-format","plugin","serialization"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}