Skip to content

combineLatest only throws cryptic error at subscription runtime instead of clear type error #7306

Open
@Patrick-DS-Smartly

Description

@Patrick-DS-Smartly

Describe the bug

I noticed this bug by using combineLatest in the following way (you can run this in a REPL for example)

const { combineLatest, of } = require('rxjs')
combineLatest([of(0), undefined]).subscribe()

which gives the corresponding stacktrace:

TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.
    at Object.createInvalidObservableTypeError (<path-to-my-project>/node_modules/rxjs/dist/cjs/internal/util/throwUnobservableError.js:5:12)
    at Object.innerFrom (<path-to-my-project>/node_modules/rxjs/dist/cjs/internal/observable/innerFrom.js:93:36)
    at Object.from (<path-to-my-project>/node_modules/rxjs/dist/cjs/internal/observable/from.js:7:78)
    at <path-to-my-project>/node_modules/rxjs/dist/cjs/internal/observable/combineLatest.js:42:41
    at maybeSchedule (<path-to-my-project>/node_modules/rxjs/dist/cjs/internal/observable/combineLatest.js:72:9)
    at _loop_1 (<path-to-my-project>/node_modules/rxjs/dist/cjs/internal/observable/combineLatest.js:41:17)
    at <path-to-my-project>/node_modules/rxjs/dist/cjs/internal/observable/combineLatest.js:61:17
    at maybeSchedule (<path-to-my-project>/node_modules/rxjs/dist/cjs/internal/observable/combineLatest.js:72:9)

I'm ok with the error itself, but I'm not ok with the fact that the stacktrace sits entirely within the RxJS library. The issue becomes problematic in a codebase which is very large and uses RxJS extensively because it gives literally nowhere to start when the time comes to figure out which call of combineLatest caused the issue. In fact, from that stacktrace, it's not even clear that it's a call to combineLatest that caused the issue, since the only indication I have here is that combineLatest.js appears somewhere in the stacktrace.

Expected behavior

I would expect the following code

const { combineLatest, of } = require('rxjs')
combineLatest([of(0), undefined])

(without subscription) to throw the following:

TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.
    at <location in my code, not in the RxJS library>
    at <rest of the stacktrace>.

Reproduction code

const { combineLatest, of } = require('rxjs')
combineLatest([of(0), undefined])

Reproduction URL

https://stackblitz.com/edit/rxjs-gdmq8d?file=index.ts

Version

7.8.0

Environment

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions