firebase / firebase-admin-node

Firebase Admin Node.js SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
1.6k stars 358 forks source link

Firebase errors are exported as stubs #2582

Open noahw3 opened 4 weeks ago

noahw3 commented 4 weeks ago

[READ] Step 1: Are you in the right place?

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

The new error types that are exported in 12.1.1 are great and make error handling much easier. However, the TS interfaces are notably lacking constructors - they just extend all the way to Error. The actual implementations take info: ErrorInfo, message?: string parameters to set the underlying code and message properties.

This means that in testing code I'm not able to really take advantage of the new types without casting or playing other type shenanigans in order to set the properties as expected, which significantly limits the usefulness of these newly exported types.

Relevant Code:

// In a node REPL

> let err = new FirebaseAuthError("test error message")
undefined
> err.code
'auth/undefined'
> err.message
undefined

> let err2 = new FirebaseAuthError({ message: "test error 2", code: "val"  })
undefined
> err2.code
'auth/val'
> err2.message
'test error 2'

// In typescript
// Argument of type '{ message: string; code: string; }' is not assignable to parameter of type 'string'.
const error = new FirebaseAuthError({ message: "test error 2", code: "val"  });

Relates to https://github.com/firebase/firebase-admin-node/pull/2549

lahirumaramba commented 3 weeks ago

Hey @noahw3, thanks for reporting this! We need a complete error handling revamp in the SDK, but since that was not currently in the roadmap we merged #2549 as a stopgap. The constructors are currently marked as private... I will look into this issue to see what else we can to do improve the exposed error types