Custom Errors not rendering

I have reported this bug Certain Custom Error messages don't get displayed properly · Issue #87 · observablehq/feedback · GitHub

Here is a notebook that demonstrates the FirebaseError do not render properly.

Its something to do with message being an accessor and maybe typescript is implicated but I feel like it’s a bug in the Error detection routine. I have seen this problem in Google API clients too, so I feel like its a path other libraries might suffer from.

Here is FirebaseError implementation: firebase-js-sdk/errors.ts at 5ad7ff2ae955c297556223e6cb3ad9d4b897f664 · firebase/firebase-js-sdk · GitHub. Its not particularly outlandish other than being written in Typescript

Hello,

This is not really Firebase-related. You’d get the same from throw {a:1}.
This is because the error object that’s thrown from Firebase does not implement a toString method. Since the object thrown could be whatever, Observable can’t really know what to do with it.
It’d be better if Firebase derived its error object from the standard Error type…

Edit: sorry, I hadn’t seen the Firebase code.

Probably related to this: https://stackoverflow.com/a/41102182

2 Likes

+1 to what @edeboursetty said. Extending Error would give the correct toString behavior and a stack trace.

1 Like

Thanks for the link. Yeah seems to be TS compiler targeting ES5

’ the problem is that the TypeScript compiler is transpiling to ES5, and Error cannot be correctly subclassed using only ES5 features;’

not sure to fix this… I guess recompile the SDK with a different target is the right move (?)

I guess Google API clients similarly are targeting ES5 too.

well I bumped the dependancy version and the errors work now (see notebook)
I changed SDK version from 7.21.0 to 8.4.1
I looked at the git (tags/firebase@7.21.0) to see what was different and I could not see any changes so the mystery remains as to the root cause but my immediate problems are solved.

You were looking at the wrong file. FirebaseStorageError is defined here and was changed to extend from FirebaseError in October '20.

Take a closer look at the screenshot that I shared in Certain Custom Error messages don't get displayed properly · Issue #87 · observablehq/feedback · GitHub

1 Like