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

Add failure reason to messaging NSError #5511

Merged
merged 6 commits into from
May 1, 2020
Merged

Conversation

charlotteliang
Copy link
Contributor

@charlotteliang charlotteliang commented Apr 30, 2020

Currently Messaging returns a NSError with an internal error code (integer) and they don't mean anything to developers and very hard to track the cause. e.g. when subscribing to a empty topic, it returns error code 8.
Add failure reason to each error to what went wrong.
Also remove unused the error code.
At some point we should deprecate the FIRMessagingErrorCode as many is unused and not very useful for developers to debug.

Copy link
Contributor

@maksymmalyhin maksymmalyhin left a comment

Choose a reason for hiding this comment

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

Great! Mostly LGTM, one question.

NSError *error = [NSError fcm_errorWithCode:FIRMessagingErrorInvalidRequest
userInfo:@{NSLocalizedDescriptionKey : description}];
NSError *error = [NSError
messagingErrorWithCode:(FIRMessagingInternalErrorCode)FIRMessagingErrorInvalidRequest
Copy link
Contributor

Choose a reason for hiding this comment

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

Casting to FIRMessagingInternalErrorCode doesn't look nice and leads to a couple questions:

  1. If we don't care of the actual code why we require it in the method interface
  2. If we do care of the code, then after casting from an unrelated enum the code may actually change meaning.

I wonder if there is a reason for this type casting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. I guess we don't have to require in the method interface, so should I just use NSUInteger?
  2. This was the old structure where somehow we kept two list of error codes, an internal and an external. My guess is adding an external requires API change, also external one is the one will be exposed to external API. I also notice the internal one makes a copy of the external one for easy casting.

I think we should deprecate the external error codes as they don't really mean anything to users, especially once failure reason is set and shown, the error doesn't even show the error code anymore, which is much clearer to users.
WDYT?

Copy link
Contributor

@maksymmalyhin maksymmalyhin Apr 30, 2020

Choose a reason for hiding this comment

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

Specific codes for specific errors can be useful for the case when developers can actually react to them. Taking this into account I would suggest to reduce amount of public error codes to the cases that can be handled differently. Ideally, the public codes should go through API review.

As for NSUInteger, I'm a bit hesitant doing it since usually error codes are meaningful within an error domain. Can we just use a code from FIRMessagingInternalErrorCode enum so we don't have to cast and can be sure that the code is interpreted properly in the proper domain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean using internal code, but has a public code with the same value to represent the meaning of it?

Because if we use internal code, we are not actually using the public one at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated to use internal one only (renamed to FIRMessagingErrorCode)

@charlotteliang
Copy link
Contributor Author

Submit for now for hackweek and let's talk more on the public error code

@charlotteliang charlotteliang merged commit 416e8d7 into master May 1, 2020
@charlotteliang charlotteliang deleted the messaging-error-code branch May 1, 2020 19:53
@firebase firebase locked and limited conversation to collaborators Jun 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants