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

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

Open
Patrick-DS-Smartly opened this issue Jul 12, 2023 · 0 comments

Comments

@Patrick-DS-Smartly
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant