-
Notifications
You must be signed in to change notification settings - Fork 923
Ensure errors are wrapped in FirestoreError in DatastoreImpl methods #4788
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
Ensure errors are wrapped in FirestoreError in DatastoreImpl methods #4788
Conversation
🦋 Changeset detectedLatest commit: 7bbbfe5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Size Analysis Report |
Binary Size ReportAffected SDKs
Test Logs |
|
||
use(chaiAsPromised); | ||
|
||
// TODO: Improve the coverage of these tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a bug number or a user name (e.g. wilhuff
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Promise.reject(new FirestoreError(Code.ABORTED, 'zzyzx')); | ||
const credentials = new MockCredentialsProvider(); | ||
const datastore = newDatastore(credentials, connection, serializer); | ||
await expect(invokeDatastoreImplInvokeStreamingRPC(datastore)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to verify that we return a FirestoreError. I think you can do this as such:
await expect(invokeDatastoreImplInvokeStreamingRPC(datastore)).to.be.eventually.rejectedWIth(new FirestoreError(Code.ABORTED, 'zzyzx'))
If that doesn't work, you can use a try/catch here.
This also applies to other tests such as"DatastoreImpl.invokeRPC() wraps unknown exceptions in a FirestoreError". Since GRPC errors also have codes, I suspect that these tests may have passed even without your change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Unfortunately, the "nice" way of using rejectedWith
as you suggest doesn't work. The check incorrectly fails with this message:
AssertionError: expected promise to be rejected with 'FirebaseError: [code=unknown]: zzyzx' but it was rejected with 'FirebaseError: [code=unknown]: zzyzx'
(note: both the actual and expected strings in the message are equal)
But I found that you can verify multiple properties at once. So I used that to verify that the name
is FirebaseError
in addition to verifying the code.
Fixes: #4780