Skip to content

Change driveGen to throw errors instead of returning UnhandledException#30

Merged
adelrodriguez merged 1 commit intomainfrom
03-07-change_drivegen_to_throw_errors_instead_of_returning_unhandledexception_
Mar 7, 2026
Merged

Change driveGen to throw errors instead of returning UnhandledException#30
adelrodriguez merged 1 commit intomainfrom
03-07-change_drivegen_to_throw_errors_instead_of_returning_unhandledexception_

Conversation

@adelrodriguez
Copy link
Copy Markdown
Owner

This pull request changes the error handling behavior in the generator execution system from wrapping exceptions in UnhandledException to throwing the original errors directly.

Key Changes:

  • Generator execution now throws original errors: The driveGen function no longer catches and wraps exceptions in UnhandledException. Instead, it allows the original errors to propagate naturally.

  • Preserved control error handling: Special error types like TimeoutError, CancellationError, and Panic continue to be preserved and thrown as-is, maintaining their specific error semantics.

  • Simplified async error propagation: Rejected promises in the async execution path now reject with their original reasons rather than being wrapped in UnhandledException.

  • Updated type assertions: Test type assertions now include UnhandledException in the expected union types to reflect that it can still be returned in certain error scenarios.

  • Comprehensive test updates: All tests have been updated to expect thrown errors using try-catch blocks instead of checking return values, including tests for factory errors, generator body errors, promise rejections, and non-Error thrown values.

The change makes error handling more predictable by preserving the original error types and stack traces while maintaining backward compatibility for control flow errors.

Copy link
Copy Markdown
Owner Author

adelrodriguez commented Mar 7, 2026

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 7, 2026

Warning

Rate limit exceeded

@adelrodriguez has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 1 minutes and 5 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 95e856f8-b14e-4749-a955-c8cd719c9a0a

📥 Commits

Reviewing files that changed from the base of the PR and between 56c3a30 and 28f232d.

📒 Files selected for processing (4)
  • src/__tests__/types.test.ts
  • src/lib/__tests__/gen.test.ts
  • src/lib/executors/__tests__/base.test.ts
  • src/lib/gen.ts

Walkthrough

This PR refactors error handling in generator execution logic. The changes simplify error propagation by removing UnhandledException wrapping behavior and eliminating ControlError handling. Type assertions in tests are updated to include UnhandledException in the possible return types. Test files are rewritten to use try/catch blocks instead of expecting wrapped exceptions, verifying direct error propagation for yielded promises, final promises, and factory/generator errors. A wrapper test parameter is adjusted to ignore execution context.

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately summarizes the main change: switching from returning UnhandledException to throwing errors directly in driveGen.
Description check ✅ Passed The description is directly related to the changeset, detailing the error handling modifications across multiple files and explaining the motivation and implementation approach.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 03-07-change_drivegen_to_throw_errors_instead_of_returning_unhandledexception_

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.

@adelrodriguez adelrodriguez marked this pull request as ready for review March 7, 2026 17:37
Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Copy Markdown

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lib/gen.ts`:
- Line 25: executeAsyncGenerator currently awaits promises (e.g., the assignment
to currentValue from initialValue and the awaits around lines 45–46) which lets
rejected promises short-circuit the async generator and skip generator-local
catch/finally blocks; change those awaits to try/catch blocks that on rejection
call iterator.throw(error) to re-inject the error into the generator before
rethrowing (preserve returned/rejected behavior), so generator cleanup runs;
update executeAsyncGenerator's logic where it awaits initialValue/currentValue
and the later awaits to wrap awaits with try { currentValue = await ... } catch
(err) { await safeIteratorThrow(iterator, err); throw err; } and add a
regression test like try/finally { yield* use(Promise.reject(...)) } to ensure
finally runs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d4778ec8-e56a-4588-924b-239100877c70

📥 Commits

Reviewing files that changed from the base of the PR and between beb4d28 and 56c3a30.

📒 Files selected for processing (4)
  • src/__tests__/types.test.ts
  • src/lib/__tests__/gen.test.ts
  • src/lib/executors/__tests__/base.test.ts
  • src/lib/gen.ts

@adelrodriguez adelrodriguez force-pushed the 03-07-change_drivegen_to_throw_errors_instead_of_returning_unhandledexception_ branch from 56c3a30 to 28f232d Compare March 7, 2026 18:04
@adelrodriguez adelrodriguez merged commit 6c0cfde into main Mar 7, 2026
7 checks passed
@adelrodriguez adelrodriguez deleted the 03-07-change_drivegen_to_throw_errors_instead_of_returning_unhandledexception_ branch March 7, 2026 18:08
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 28f232dc46

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 42 to +44
} catch (error) {
if (checkIsControlError(error)) {
return error as GenErrors<TYield>
}

return new UnhandledException(undefined, { cause: error }) as GenErrors<TYield>
currentStep = iterator.throw(error)
continue
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Bypass generator catch for control-error rejections

Rejected yielded promises are now always fed back with iterator.throw(error), including TimeoutError/CancellationError/Panic. In this path, a generator try/catch (or finally with return) can swallow those control errors and return a success value, so cancellation/timeout can be silently ignored instead of propagating. Before this commit, these control errors were returned immediately and could not be intercepted by generator code, which preserved fail-fast control semantics.

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant