Skip to content

assert supports cause - #1232

Merged
snakajima merged 3 commits into
receptron:mainfrom
isamu:assertCause
Oct 3, 2025
Merged

snakajima merged 3 commits into
receptron:mainfrom
isamu:assertCause

Conversation

@isamu

@isamu isamu commented Oct 3, 2025 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Improvements
    • Enhanced error reporting to include an underlying cause when available, improving debuggability without changing normal behavior.
  • Chores
    • Updated TypeScript compilation target to ES2022 for broader modern JavaScript compatibility.
  • Tests
    • Added unit tests to verify error cause propagation and ensure reliability.

@isamu
isamu requested a review from snakajima October 3, 2025 20:31
@coderabbitai

coderabbitai Bot commented Oct 3, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Compiler target updated to ES2022. The assert utility gains an optional cause parameter to include underlying error causes when throwing. Unit tests are extended to cover the new cause behavior and import the assert function for testing.

Changes

Cohort / File(s) Summary
TypeScript config
config/tsconfig.base.json
Update compiler target from es2021 to es2022.
Utils: assert enhancement
packages/graphai/src/utils/utils.ts
Add optional cause?: unknown to assert. When failing and not warning, throw new Error(message, { cause }) if cause provided; otherwise throw new Error(message). Signature updated accordingly.
Tests: error handling
packages/graphai/tests/units/test_error.ts
Import assert as GraphaiAssert. Add test verifying thrown Error includes name, message, and cause when cause is supplied. Existing tests unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Caller
  participant U as utils.assert
  participant E as Error

  C->>U: assert(condition, message, isWarn=false, cause?)
  alt condition is true
    U-->>C: returns
  else condition is false and isWarn is true
    U-->>C: logs/warns and returns
  else condition is false and isWarn is false
    alt cause provided
      U->>E: new Error(message, { cause })
    else no cause
      U->>E: new Error(message)
    end
    U--xC: throws Error
  end
  note over U,E: Throw path now includes optional cause
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nudge my nose at ES2022 air,
With gentle thumps I test errors with care.
A cause in the burrow, now neatly attached,
If checks should fail, the tale is dispatched.
Hop, log, throw—trace the path I choose,
In tidy trails no clues we’ll lose. 🐇✨

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly summarizes the primary change of adding support for a cause parameter to the assert function, directly reflecting the core update in the changeset. It is concise, specific, and free of extraneous details, ensuring that a reviewer can immediately grasp the main purpose of the pull request. This phrasing aligns well with the guideline of highlighting the most important developer-visible change.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6571488 and dbb0140.

📒 Files selected for processing (3)
  • config/tsconfig.base.json (1 hunks)
  • packages/graphai/src/utils/utils.ts (1 hunks)
  • packages/graphai/tests/units/test_error.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/graphai/src/utils/utils.ts (1)
packages/graphai/src/index.ts (1)
  • assert (39-39)
⏰ 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). (2)
  • GitHub Check: build (24.x)
  • GitHub Check: build (22.x)
🔇 Additional comments (5)
packages/graphai/tests/units/test_error.ts (2)

1-1: LGTM! Import updated to include assert for testing.

The import statement now includes assert as GraphaiAssert to enable testing of the assert function with the new cause parameter.


133-140: LGTM! Test coverage added for error cause.

The new test validates that the assert function correctly includes the cause when throwing errors, ensuring the Error.cause feature works as expected.

packages/graphai/src/utils/utils.ts (2)

38-38: LGTM! Function signature updated to support error cause.

The assert function now accepts an optional cause parameter, enabling richer error context when assertions fail.


41-43: LGTM! Error cause correctly propagated.

The implementation correctly checks for the presence of cause and includes it in the thrown Error when provided, leveraging the ES2022 Error.cause feature.

config/tsconfig.base.json (1)

14-14: Verify Node.js and browser support for ES2022
No engines.node field found in your project’s package.json—add an engine requirement (e.g. "node": ">=16.9.0") to guarantee Error cause support, and confirm your target browsers support ES2022.


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.

@snakajima
snakajima merged commit e994a10 into receptron:main Oct 3, 2025
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.

2 participants