Skip to content

fix(es/transforms): Fix SuppressedError for resource management #10915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kdy1
Copy link
Member

@kdy1 kdy1 commented Jul 21, 2025

Description:

  • Fixed argument order in SuppressedError constructor to match TypeScript spec
  • Changed from new SuppressedError(oldError, newError) to new SuppressedError(newError, oldError)
  • Added comprehensive tests for multiple disposables throwing errors

Related issue:

…esource management

- Fixed argument order in SuppressedError constructor to match TypeScript spec
- Changed from new SuppressedError(oldError, newError) to new SuppressedError(newError, oldError)
- Added comprehensive tests for multiple disposables throwing errors

Fixes #8853

Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
@kdy1 kdy1 added this to the Planned milestone Jul 21, 2025
@kdy1 kdy1 self-assigned this Jul 21, 2025
Copy link

changeset-bot bot commented Jul 21, 2025

⚠️ No Changeset found

Latest commit: aa1c9d8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

claude bot commented Jul 21, 2025

Claude finished @kdy1's task —— View job


Code Review for PR #10915: Fix SuppressedError for Resource Management

Todo List

  • Read modified helper files (_using_ctx.js)
  • Review new test files for coverage
  • Analyze code quality and potential issues
  • Assess security and performance implications
  • Provide comprehensive review feedback

Review Findings

Code Quality - Excellent

The Fix is Correct: The argument order change in crates/swc_ecma_transforms_base/src/helpers/_using_ctx.js:68 and packages/helpers/esm/_using_ctx.js:63 is spot-on:

// Fixed: new error first, then suppressed error  
new _disposeSuppressedError(e, error)

This matches the ECMAScript specification for SuppressedError(error, suppressed[, message]) where the first parameter is the primary error.

Test Coverage - Outstanding

The new test files demonstrate excellent coverage:

  • Comprehensive scenarios: Both sync and async disposal patterns
  • Complex error chaining: Tests multiple disposables (4) throwing errors in sequence
  • Precise verification: Validates the exact error structure and chaining order
  • Clear documentation: Comments explain the disposal order and expected behavior

The tests verify the correct behavior where disposal happens in reverse order (_x4 → _x3 → _x2 → _x1) and errors are properly chained.

No Security Concerns

  • No exposure of sensitive data
  • Standard error handling patterns
  • No injection vulnerabilities

Performance - No Impact

  • Minimal change to existing logic
  • No additional computational overhead
  • Same memory allocation patterns

Potential Issues - None Identified

Edge Cases Well-Handled:

  • Polyfill fallback for environments without native SuppressedError
  • Proper null/undefined handling in the using context
  • Consistent behavior between sync/async paths

🎯 Specification Compliance

This fix brings SWC's implementation in line with:

Recommendation: ✅ APPROVE

This is a high-quality fix that:

  1. Resolves a clear specification compliance issue
  2. Includes comprehensive test coverage
  3. Has no performance or security implications
  4. Maintains backward compatibility (error behavior change is a bug fix)

The implementation is clean, well-tested, and follows established patterns in the codebase.


Copy link

codspeed-hq bot commented Jul 21, 2025

CodSpeed Performance Report

Merging #10915 will not alter performance

Comparing claude/issue-8853-20250721-1753 (aa1c9d8) with main (c1405da)1

Summary

✅ 140 untouched benchmarks

Footnotes

  1. No successful run was found on main (a44d329) during the generation of this report, so c1405da was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@github-actions github-actions bot modified the milestones: Planned, 1.13.5 Aug 24, 2025
@kdy1 kdy1 modified the milestones: 1.13.5, Planned Aug 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

swc explicitResourceManagement SuppressedError implement does not obey spec
2 participants