vitest-dev/vitest · error · PrettyFormatPluginError
error.message
Error message
error.message
What it means
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.
Defensive patterns
Strategy: try-catch
Try / catch
try {
format(value, { plugins })
} catch (e) {
if (e instanceof PrettyFormatPluginError) {
// inspect original plugin error via e.stack; disable/fallback plugin
format(value, { plugins: plugins.filter(p => p !== suspect) })
} else throw e
} Prevention
- Keep custom plugins defensive (try/catch internally)
- Pin plugin versions compatible with pretty-format
- Test plugins against the value shapes they will encounter
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Asymmetric matcher does not implement toAsymmetricMatcher()
- pretty-format: Plugin must return type "string" but instead…
- Cannot provide " " because it's not serializable.
- Cannot set serialized manual mock. Define a factory…
- Expected DOM element to be an instance of Element, received
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/ba12c90670e0dc47.
Report an issue: GitHub.
Appendix: source
Thrown at packages/pretty-format/src/index.ts:355
val,
valChild => printer(valChild, config, indentation, depth, refs),
(str) => {
const indentationNext = indentation + config.indent
return (
indentationNext
+ str.replaceAll(NEWLINE_REGEXP, `\n${indentationNext}`)
)
},
{
edgeSpacing: config.spacingOuter,
min: config.min,
spacing: config.spacingInner,
},
config.colors,
)
}
catch (error: any) {
throw new PrettyFormatPluginError(error.message, error.stack)
}
if (typeof printed !== 'string') {
throw new TypeError(
`pretty-format: Plugin must return type "string" but instead returned "${typeof printed}".`,
)
}
return printed
}
function findPlugin(plugins: Plugins, val: unknown) {
for (const plugin of plugins) {
try {
if (plugin.test(val)) {
return plugin
}
}
catch (error: any) {
throw new PrettyFormatPluginError(error.message, error.stack)View on GitHub (pinned to 1fa9837ec2)