Skip to content

Scripts: Log error cause for generate task#34754

Merged
JReinhold merged 1 commit into
nextfrom
fix/better_generate_err_logs
May 12, 2026
Merged

Scripts: Log error cause for generate task#34754
JReinhold merged 1 commit into
nextfrom
fix/better_generate_err_logs

Conversation

@huang-julien
Copy link
Copy Markdown
Contributor

@huang-julien huang-julien commented May 9, 2026

Closes #

What I did

When Aa generate task fails, there's no information on what error caused the task to fail;

This PR adds source errors to throwned errors

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

image

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

  • Chores
    • Improved error handling in sandbox generation with enhanced error cause tracking, providing better diagnostics when yarn setup or generation failures occur.

Review Change Stack

@huang-julien huang-julien added bug build Internal-facing build tooling & test updates ci:merged Run the CI jobs that normally run when merged. labels May 9, 2026
@huang-julien huang-julien changed the title Scripts: log error cause Scripts: Log error cause for generate task May 9, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 9, 2026

📝 Walkthrough

Walkthrough

The pull request improves error propagation in the sandbox generation script by adding Error cause objects to thrown errors. Yarn setup failures and sandbox generation failures now preserve and attach underlying error objects, enabling better error context and debugging information throughout the failure chain.

Changes

Error Cause Propagation

Layer / File(s) Summary
Yarn Setup Error Cause
scripts/sandbox/generate.ts
When yarn setup fails, the thrown error now includes the underlying caught error as a cause property instead of discarding it.
Generation Failure Error Propagation
scripts/sandbox/generate.ts
When sandbox generation fails (both in the immediate throw for non-CI/STORYBOOK_SANDBOX_GENERATE environments and the deferred throw after GitHub Actions summary), aggregated "Some sandboxes failed to generate" errors now include a cause containing rejected generation results' underlying error objects.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
scripts/sandbox/generate.ts (1)

334-341: ⚡ Quick win

Consider using AggregateError instead of an array in cause.

Passing an array of errors as the cause property is non-standard. Error monitoring and logging tools typically expect Error.cause to be a single Error object, not an array. Node.js provides AggregateError (available since v15.0.0) specifically for representing multiple errors.

♻️ Refactor to use AggregateError
-      throw new Error(`Some sandboxes failed to generate`, {
-        cause: generationResults
-          .filter((result) => result.status === 'rejected')
-          .map((result) => {
-            const generationError = (result as PromiseRejectedResult).reason as Error;
-            return generationError;
-          }),
-      });
+      throw new AggregateError(
+        generationResults
+          .filter((result) => result.status === 'rejected')
+          .map((result) => (result as PromiseRejectedResult).reason),
+        'Some sandboxes failed to generate'
+      );
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/sandbox/generate.ts` around lines 334 - 341, Replace the thrown Error
that uses an array in its cause with an AggregateError: collect the rejected
promises from generationResults (the current .filter/.map that produces
generationError from PromiseRejectedResult) into an array of Error objects and
throw new AggregateError(errorsArray, 'Some sandboxes failed to generate')
instead of throw new Error(...); ensure you remove the array-as-cause usage and
reference the existing generationResults and generationError variables when
building the AggregateError.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@scripts/sandbox/generate.ts`:
- Around line 334-341: Replace the thrown Error that uses an array in its cause
with an AggregateError: collect the rejected promises from generationResults
(the current .filter/.map that produces generationError from
PromiseRejectedResult) into an array of Error objects and throw new
AggregateError(errorsArray, 'Some sandboxes failed to generate') instead of
throw new Error(...); ensure you remove the array-as-cause usage and reference
the existing generationResults and generationError variables when building the
AggregateError.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7602194f-caf2-4e83-a29d-b40ab69a5549

📥 Commits

Reviewing files that changed from the base of the PR and between b2167d6 and f8ad130.

📒 Files selected for processing (1)
  • scripts/sandbox/generate.ts

@huang-julien huang-julien removed the bug label May 9, 2026
@storybook-app-bot
Copy link
Copy Markdown

Package Benchmarks

Commit: f8ad130, ran on 9 May 2026 at 11:59:33 UTC

The following packages have significant changes to their size or dependencies:

@storybook/cli

Before After Difference
Dependency count 194 194 0
Self size 906 KB 890 KB 🎉 -16 KB 🎉
Dependency size 84.49 MB 84.49 MB 🚨 +1 KB 🚨
Bundle Size Analyzer Link Link

@huang-julien huang-julien requested a review from JReinhold May 11, 2026 07:44
@JReinhold JReinhold merged commit cc871df into next May 12, 2026
178 of 199 checks passed
@JReinhold JReinhold deleted the fix/better_generate_err_logs branch May 12, 2026 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-scan:human build Internal-facing build tooling & test updates ci:merged Run the CI jobs that normally run when merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants