Skip to content

Conversation

@yannbf
Copy link
Member

@yannbf yannbf commented Jan 7, 2026

Closes #

What I did

Small but important fix, sometimes when running tests through the testing widget, the error message was not included in the error stack and on FATAL_ERROR we would end up missing that important bit of information before logging to the user. This PR fixes that.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

Caution

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • Bug Fixes
    • Improved error stack trace formatting to ensure error messages are properly preserved alongside stack information, enhancing error readability and debugging clarity.

✏️ Tip: You can customize this high-level summary in your review settings.

@nx-cloud
Copy link

nx-cloud bot commented Jan 7, 2026

View your CI Pipeline Execution ↗ for commit 28405e0

Command Status Duration Result
nx run-many -t compile,check,knip,test,pretty-d... ✅ Succeeded 8m 14s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-07 20:51:05 UTC

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 7, 2026

📝 Walkthrough

Walkthrough

The errorToErrorLike utility function in the vitest addon is modified to preserve the original error message by concatenating it with the stack trace, effectively re-inserting the message at the start of the stack string. Other error handling logic remains unchanged.

Changes

Cohort / File(s) Summary
Error stack formatting
code/addons/vitest/src/utils.ts
Modified errorToErrorLike to concatenate error message with stack trace, preserving the original message at the start of the stack string

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In @code/addons/vitest/src/utils.ts:
- 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.
- 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.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 13b7cff and 28405e0.

📒 Files selected for processing (1)
  • code/addons/vitest/src/utils.ts
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{js,jsx,ts,tsx,json,md,html,css,scss}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Format code using Prettier with yarn prettier --write <file>

Files:

  • code/addons/vitest/src/utils.ts
**/*.{js,jsx,json,html,ts,tsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Run ESLint checks using yarn lint:js:cmd <file> or the full command cross-env NODE_ENV=production eslint --cache --cache-location=../.cache/eslint --ext .js,.jsx,.json,.html,.ts,.tsx,.mjs --report-unused-disable-directives to fix linting errors before committing

Files:

  • code/addons/vitest/src/utils.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Enable TypeScript strict mode across all packages

Files:

  • code/addons/vitest/src/utils.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx,js,jsx}: Export functions from modules if they need to be tested
Do not use console.log, console.warn, or console.error directly unless in isolated files where importing loggers would significantly increase bundle size

Files:

  • code/addons/vitest/src/utils.ts
code/{core,lib,addons,builders,frameworks,presets}/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use logger from storybook/internal/node-logger for server-side logging in Node.js code

Files:

  • code/addons/vitest/src/utils.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: normal
  • GitHub Check: nx
  • GitHub Check: Core Unit Tests, windows-latest
  • GitHub Check: nx
  • GitHub Check: nx

return {
message: error.message,
name: error.name,
// avoid duplicating the error message in the stack trace
Copy link
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.

name: error.name,
// avoid duplicating the error message in the stack trace
stack: error.stack?.replace(error.message, ''),
stack: error.message + ' ' + error.stack?.replace(error.message, ''),
Copy link
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants