Skip to content

MergeMap throws uncatchable errors #5344

@kondi

Description

@kondi

Bug Report

Current Behavior
In the sample code below, the TypeError is not caught in the catchError callback, but thrown globally. We can not detect the error in the observable stream and in NodeJS environment this error can cause the whole application to shut down.

(If the provided mergeMap callback throws an Error instead of returning null, the error is handled correctly.)

Reproduction

of(1).pipe(
  // Without the next line, the error is caught correctly
  mergeMap(async () => 2),
  // This usage should produce a runtime TypeError: You provided 'null' where a stream was expected.
  mergeMap(() => null),
  catchError(error => {
    console.error('Error in the stream caught:', error.message);
    return [];
  })
).subscribe();

Expected behavior
The TypeError should not leave the observable stream, should be catchable by catchError the same way like when the mergeMap(async () => 2) line does not present.

Environment

  • Runtime: Node v12.10.0, Chrome v80.0.3987.122
  • RxJS version: 6.5.4

Possible Solution
Not a solution, just a very hacky workaround for somebody who is affected by this bug: https://stackblitz.com/edit/rxjs-uncaught?file=patch.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions