Skip to content

replace UnobservableError "invalid object" with object type - #5915

Closed
abacaphiliac wants to merge 2 commits into
ReactiveX:masterfrom
abacaphiliac:throw-unobservable-error-spec
Closed

replace UnobservableError "invalid object" with object type#5915
abacaphiliac wants to merge 2 commits into
ReactiveX:masterfrom
abacaphiliac:throw-unobservable-error-spec

Conversation

@abacaphiliac

Copy link
Copy Markdown

Description:

My application was crashing with the following generic error.

You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, AsyncIterable, or Iterable.

Upon closer inspection, I discovered that the object was indeed an Observable. The underlying issue was that multiple versions of rxjs were installed in my application. Once I was able to see that the "invalid object" was an "Observable", I knew immediately to audit node_modules for this issue. I'm hopeful that providing additional information about this runtime error will help others.

Related issue (if exists):

None that I could find.

});
it('Should handle an Observable', () => {
const error = createInvalidObservableTypeError(from<string>('FooBar'));
expect(error.message).to.match(/^You provided type 'Observable' where a stream was expected./);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand what this is trying to do, but this error would make me want to scream if I saw it and didn't know what it meant.

"You provided type 'Observable' where a stream was expected. You can provide an Observable, Promise, Array, AsyncIterable, or Iterable."

We probably need to do something where we actually link to some documentation about what could be going on. 🤔

Or at the very least maybe it needs to say something like "unsupported Observable" or.. something that makes RxJS look less like it's losing it's mind.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, it's worth checking the ctor name against 'Observable' and saying something like:

"You provided type 'Observable' (from another package) where a stream was expected. ..."

@abacaphiliac abacaphiliac Dec 6, 2020

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the suggestions. i'll get it done. is there any documentation or are there any relevant issues that should be included in the error message?

@benlesh

benlesh commented Feb 4, 2021

Copy link
Copy Markdown
Member

I've been thinking about this, and we may want to start having error numbers and documentation links with more concise messages overall. We have to ship all of this code, after all.

Something like RX0001 - object unobservable https://rxjs.dev/errors#RX0001 or RX0002 - Foreign observable https://rxjs.dev/errors#RX0002 and so on, where we can provide detailed information about what that error means, why it's happening, and how to solve it.

@benlesh benlesh added the AGENDA ITEM Flagged for discussion at core team meetings label Jan 11, 2022
@benlesh

benlesh commented Mar 23, 2022

Copy link
Copy Markdown
Member

Core Team:

  • Not sure if this provides a ton more value than what we have.
  • People usually want to know where the returned thing was created or returned that didn't get converted to an observable.

There is an interesting proposal from 2014 by @stefanpenner brought to my attention by @ladyleet today: https://bugs.chromium.org/p/chromium/issues/detail?id=332624

Something like that might help get better context as to where something came from.

(BTW: Sorry @abacaphiliac for super late re-review)

@benlesh

benlesh commented Feb 8, 2023

Copy link
Copy Markdown
Member

CORE TEAM: We can get this in v8 maybe. It doesn't save the world, but maybe it will help someone? 🤷‍♂️

@benlesh benlesh self-assigned this Feb 8, 2023
@benlesh benlesh removed the AGENDA ITEM Flagged for discussion at core team meetings label Feb 8, 2023
@benlesh

benlesh commented Jul 22, 2026

Copy link
Copy Markdown
Member

Hi @abacaphiliac — thank you for the time, care, and thoughtfulness you put into this pull request. I’m sorry we weren’t able to respond in a reasonable timeframe. Since the codebase and surrounding context have moved on and this hasn’t seen recent activity, I’m going to close it for now. That’s a reflection of our delayed triage, not a lack of appreciation for your contribution. If the change is still relevant, please feel welcome to open a fresh pull request against the current codebase. Thank you again for contributing to RxJS and for your patience.

— Ben

@benlesh benlesh closed this Jul 22, 2026
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

Successfully merging this pull request may close these issues.

3 participants