Skip to content
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

RxJS v6 TimeoutError is missing name property #3602

Closed
felixfbecker opened this issue Apr 25, 2018 · 2 comments
Closed

RxJS v6 TimeoutError is missing name property #3602

felixfbecker opened this issue Apr 25, 2018 · 2 comments
Labels
bug Confirmed bug

Comments

@felixfbecker
Copy link
Contributor

felixfbecker commented Apr 25, 2018

RxJS version: 6.0.0

Code to reproduce:

export const browserExtensionInstalled = fromEvent(document, 'custom-event').pipe(
    mapTo(true),
    timeout(500),
    catchError(err => {
        if (err.name === 'TimeoutError') {
            return [false]
        }
        throw err
    }),
)

Expected behavior:

Should emit false after 500ms.

Actual behavior:

Throws an error Error: Timeout has occurred. (worked in RxJS 5)

Additional information:

This broke in commit 2f395da#diff-cd4b33df1ab129e23dc2bc5c12d8369b

UnsubscriptionError still has the name set, but TimeoutError doesn't, and it's not mentioned in the release notes, so I assume this is an unintentional bug (in any case it can be reintroduced in a semver-patch).

export class UnsubscriptionError extends Error {
constructor(public errors: any[]) {
super(errors ?
`${errors.length} errors occurred during unsubscription:
${errors.map((err, i) => `${i + 1}) ${err.toString()}`).join('\n ')}` : '');
this.name = 'UnsubscriptionError';
(Object as any).setPrototypeOf(this, UnsubscriptionError.prototype);
}
}

export class TimeoutError extends Error {
constructor() {
super('Timeout has occurred');
(Object as any).setPrototypeOf(this, TimeoutError.prototype);
}

Why not use instanceof? instanceof breaks when multiple RxJS versions are in play, or even just the same version had to be installed multiple times because deduping wasn't possible. It asserts the implementation, err.name asserts an interface. All browser errors use it (e.g. AbortError).

@cartant
Copy link
Collaborator

cartant commented Apr 26, 2018

This might be the first issue that'll effect a 6.0.1 release. I wonder if you get a prize? 🤔

@martinsik
Copy link
Contributor

This seems to be fixed in #3656.

@benlesh benlesh closed this as completed Oct 2, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Nov 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

4 participants