feat(errors): expose isOwnInstance to createCustomError's constructCb and skip redundant stack captures#587
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #587 +/- ##
=======================================
Coverage 99.17% 99.17%
=======================================
Files 179 179
Lines 5475 5479 +4
Branches 1209 1210 +1
=======================================
+ Hits 5430 5434 +4
Misses 45 45
🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves createCustomError to better support multi-level custom error inheritance by exposing whether a constructor is running for the leaf-most instance and by avoiding redundant internal Error.captureStackTrace calls across a base-class chain.
Changes:
- Extend
createCustomError’sconstructCbcallback to receive a 3rdisOwnInstanceargument indicating leaf-most instantiation. - Gate the internal automatic
Error.captureStackTracecall so it only runs once per instance (at the leaf-most class). - Add regression tests validating single-capture behavior and
isOwnInstancesemantics across inheritance chains.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| lib/src/helpers/customError.ts | Adds isOwnInstance detection and gates internal stack capture to avoid repeated work in inheritance chains. |
| lib/test/src/common/helpers/throw.test.ts | Adds regression tests for single stack capture and isOwnInstance behavior across direct and chained instantiation. |
nev21
force-pushed
the
nev21/CustomErrors
branch
from
July 18, 2026 05:01
1b856e1 to
d016feb
Compare
… and skip redundant stack captures Custom errors built with createCustomError can extend other custom errors, chaining constructCb calls at every level. There was previously no way for a level to know whether it was the leaf class actually being instantiated or just running as a base-class step for some subclass further down the chain, so hierarchies with their own per-level stack capture logic (e.g. a TripwireError -> AssertionError -> AssertionFailure -> AssertionFatal chain) had no way to skip that work except at the leaf. - constructCb now receives a 3rd argument, isOwnInstance, computed by comparing the instance's resolved constructor against the class's own constructor function via a self-referencing named function expression The internal automatic Error.captureStackTrace call is now gated by the same isOwnInstance check, so it only fires once per instance (at the leaf-most class) instead of redundantly at every level of a chain - Add regression tests covering the internal capture optimization and isOwnInstance correctness across single classes, multi-level chains, and a class used both directly and as a base
nev21
enabled auto-merge (squash)
July 18, 2026 05:18
nevware21-bot
approved these changes
Jul 18, 2026
nevware21-bot
left a comment
Contributor
There was a problem hiding this comment.
Approved by nevware21-bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Custom errors built with createCustomError can extend other custom errors, chaining constructCb calls at every level. There was previously no way for a level to know whether it was the leaf class actually being instantiated or just running as a base-class step for some subclass further down the chain, so hierarchies with their own per-level stack capture logic (e.g. a TripwireError -> AssertionError -> AssertionFailure -> AssertionFatal chain) had no way to skip that work except at the leaf.