-
Notifications
You must be signed in to change notification settings - Fork 27
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
Use the built-in AggregateError
when possible
#75
Comments
I will work on it. |
Hi @aleclarson This issue can be easily resolved with a small modification to the file: class AggregateErrorPolyfill extends Error {
errors: Error[]
constructor(errors: Error[] = []) {
super()
const name = errors.find(e => e.name)?.name ?? ''
this.name = `AggregateError(${name}...)`
this.message = `AggregateError with ${errors.length} errors`
this.stack = errors.find(e => e.stack)?.stack ?? this.stack
this.errors = errors
}
}
export const AggregateError = globalThis?.["AggregateError"] ?? AggregateErrorPolyfill However, this can be a bit more complicated due to the current We could resolve this in a couple of ways:
Regarding tests: The current tests check the implementation of With the current way we import the function in our tests, we will end up importing the native implementation. However, it is possible to simulate an environment where vi.stubGlobal('AggregateError', undefined)
const { AggregateError } = await import('radashi') But this would cause another type error: In this case, we would need to either use That being said, it would be useful to add two more tests to ensure that when What are your thoughts on this? |
Let's put
I think it's fine to assume Also, let's use export const AggregateError: typeof globalThis.AggregateError =
globalThis.AggregateError ??
class AggregateError {…}
I will take care of this part. Let me know when you open the PR 👍 |
Fixed in #116 |
If
globalThis.AggregateError
exists, use that instead of our polyfill. Alternatively, removeAggregateError
altogether and expect the end user to polyfill it themselves.Related issue
sodiray/radash#392
The text was updated successfully, but these errors were encountered: