-
-
Notifications
You must be signed in to change notification settings - Fork 248
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
fix(core): update nimma & json-schema #2012
Conversation
} catch (e: unknown) { | ||
if ( | ||
e instanceof Error && | ||
Array.isArray((e as Error & { errors?: unknown }).errors) && | ||
(e as Error & { errors: unknown[] }).errors.length === 1 | ||
) { | ||
const actualError = (e as Error & { errors: [unknown] }).errors[0]; | ||
throw actualError instanceof Error && 'cause' in (actualError as Error & { cause?: unknown }) | ||
? (actualError as Error & { cause: unknown }).cause | ||
: actualError; | ||
} else { | ||
throw e; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hopefully this can be simplified once AggregateError
and error causes are somehow exposed in standard lib
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what's going on here? Don't quite understand this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's to simplify testing.
Assertion of AggregateError
is shallow, meaning nested errors
are not checked.
This change makes it so we re-throw a single error so toThrow
works as expected.
In 99% (if not 100%) of cases we have a single error thrown, so that's why we unpack that AggregateError.
Makes sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously we threw a single exception when AggregateErrors.errors.length === 1
, but I simplified it in the code.
This, however, meant we needed to move that logic in here, but it's a test helper.
} catch (e) { | ||
if (isAggregateError(e) && e.errors.length === 1) { | ||
throw e.errors[0]; | ||
} else { | ||
throw e; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have a Q re the change in the test file - otherwise straight forward enough.
} catch (e: unknown) { | ||
if ( | ||
e instanceof Error && | ||
Array.isArray((e as Error & { errors?: unknown }).errors) && | ||
(e as Error & { errors: unknown[] }).errors.length === 1 | ||
) { | ||
const actualError = (e as Error & { errors: [unknown] }).errors[0]; | ||
throw actualError instanceof Error && 'cause' in (actualError as Error & { cause?: unknown }) | ||
? (actualError as Error & { cause: unknown }).cause | ||
: actualError; | ||
} else { | ||
throw e; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what's going on here? Don't quite understand this change.
# [@stoplight/spectral-core-v1.8.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-core-v1.8.0...@stoplight/spectral-core-v1.8.1) (2021-12-29) ### Bug Fixes * **core:** update nimma & json-schema ([#2012](#2012)) ([67a6104](67a6104))
🎉 This PR is included in version @stoplight/spectral-core-v1.8.1 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
# [@stoplight/spectral-functions-v1.5.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-functions-v1.5.0...@stoplight/spectral-functions-v1.5.1) (2021-12-29) ### Bug Fixes * **core:** update nimma & json-schema ([#2012](#2012)) ([67a6104](67a6104))
🎉 This PR is included in version @stoplight/spectral-functions-v1.5.1 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
Fixes #1999
Checklist
Does this PR introduce a breaking change?
Additional context
List of notable changes