From 897fc186cef0ac400146e7e9cc4c99c4ba69dd90 Mon Sep 17 00:00:00 2001 From: Arthur Fontaine <0arthur.fontaine@gmail.com> Date: Wed, 10 Dec 2025 16:01:44 +0100 Subject: [PATCH] Display error .cause property fixes #3186 --- lib/reporters/colors.js | 3 +++ lib/reporters/default.js | 11 +++++++++++ lib/serialize-error.js | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/reporters/colors.js b/lib/reporters/colors.js index 644e897df..4c6397eea 100644 --- a/lib/reporters/colors.js +++ b/lib/reporters/colors.js @@ -34,6 +34,9 @@ const colors = { get stack() { return chalk.red; }, + get cause() { + return chalk.cyan; + }, get information() { return chalk.magenta; }, diff --git a/lib/reporters/default.js b/lib/reporters/default.js index 10ca84f65..fd7584fc2 100644 --- a/lib/reporters/default.js +++ b/lib/reporters/default.js @@ -463,6 +463,17 @@ export default class Reporter { } } + const hasCause = error.cause instanceof Object && (error.cause.message || error.cause.stack); + if (hasCause) { + const {cause} = error; + this.lineWriter.writeLine(colors.cause('Cause:')); + this.lineWriter.writeLine(colors.cause(cause.message ?? '')); + if (cause.stack) { + this.lineWriter.writeLine(colors.cause(cause.stack)); + } + this.lineWriter.writeLine(); + } + let summary = ''; let printStack = true; if (error.type === 'native') { diff --git a/lib/serialize-error.js b/lib/serialize-error.js index ca47a6350..55db25465 100644 --- a/lib/serialize-error.js +++ b/lib/serialize-error.js @@ -61,12 +61,13 @@ export default function serializeError(error, {testFile = null} = {}) { }; } - const {message, name, stack} = error; + const {message, name, stack, cause} = error; const base = { message, name, originalError: error, // Note that the main process receives a structured clone. stack, + cause, }; if (!isAvaAssertionError(error)) {