Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/addons/vitest/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function errorToErrorLike(error: Error): ErrorLike {
message: error.message,
name: error.name,
// avoid duplicating the error message in the stack trace
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Update the misleading comment.

The comment states "avoid duplicating the error message" but the code on line 8 now explicitly prepends the error message to the stack. Update the comment to reflect the actual intent, such as "ensure the error message is included in the stack trace."

📝 Proposed fix
-    // avoid duplicating the error message in the stack trace
+    // ensure the error message is included in the stack trace
     stack: error.message + ' ' + error.stack?.replace(error.message, ''),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// avoid duplicating the error message in the stack trace
// ensure the error message is included in the stack trace
stack: error.message + ' ' + error.stack?.replace(error.message, ''),
🤖 Prompt for AI Agents
In @code/addons/vitest/src/utils.ts at line 7, Update the misleading comment
above the stack-manipulation logic in utils.ts: replace "avoid duplicating the
error message in the stack trace" with a comment that reflects the actual
behavior such as "ensure the error message is included in the stack trace" so
the comment accurately describes that the code prepends the error message to the
stack.

stack: error.stack?.replace(error.message, ''),
stack: error.message + ' ' + error.stack?.replace(error.message, ''),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Handle undefined error.stack to prevent malformed output.

If error.stack is undefined, the optional chaining returns undefined, and the string concatenation produces "message undefined" (e.g., "Something went wrong undefined"), which is incorrect.

🐛 Proposed fix
-    stack: error.message + ' ' + error.stack?.replace(error.message, ''),
+    stack: error.stack ? `${error.message}\n${error.stack.replace(error.message, '')}` : error.message,

This ensures:

  • If error.stack exists, the message is prepended with a newline separator (conventional format).
  • If error.stack is undefined, the stack field contains just the error message.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
stack: error.message + ' ' + error.stack?.replace(error.message, ''),
stack: error.stack ? `${error.message}\n${error.stack.replace(error.message, '')}` : error.message,
🤖 Prompt for AI Agents
In @code/addons/vitest/src/utils.ts at line 8, The stack field currently
concatenates error.message with error.stack using optional chaining which yields
"message undefined" when error.stack is missing; update the expression used for
the stack property so it checks error.stack first and, if present, returns
error.message + '\n' + error.stack.replace(error.message, '') (or similar
newline-separated formatting), otherwise just return error.message; locate the
object building the stack property (the line with stack: error.message + ' ' +
error.stack?.replace(error.message, '')) and replace it with a conditional that
avoids referencing undefined error.stack.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the stack usually contain the error.message string?

So would this code cause the error.message to be in the string twice, but only get replaced once?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug here is that the stack did not contain the error message and the actual message was never visible to the user which is bad. In the unlikely chance that there's an error message in the stack, it will get replaced and therefore you will only ever see the error message once.

cause: error.cause && error.cause instanceof Error ? errorToErrorLike(error.cause) : undefined,
};
}