-
-
Notifications
You must be signed in to change notification settings - Fork 70
Added public initializer to the ParseError struct #106
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
Conversation
Codecov Report
@@ Coverage Diff @@
## main #106 +/- ##
==========================================
- Coverage 81.02% 81.02% -0.01%
==========================================
Files 65 65
Lines 5477 5480 +3
==========================================
+ Hits 4438 4440 +2
- Misses 1039 1040 +1
Continue to review full report at Codecov.
|
Thanks for your PR... This was done on purpose as errors generated from the server and client are considered Parse Errors. Other errors are left to the developer. You should be able to create custom errors outside of Parse Errors within your app or SDK. |
Hm, well that would mean that the app can't fulfil the I think we either need to make it so you can create ParseErrors outside of the SDK, or change the authentication handler response to accept generic Swift Errors instead of needing a ParseError. |
I currently don't see why this would be needed. Parse Swift doesn't use classes, so there's no subclasses available or needed for any of the Authentication methods. It's all protocol and struct based. I think once you open a PR and start implementing it I will be able to show how to populate the error as it won't be direct rip from the objective-c implementation which seems like what you are describing. When you crate the PR, you are adding the authentication method to the SDK, meaning it has access to ParseError and can use the internal member wise initializer, you don't need the member wise initializer to be public inside the SDK. Outside the SDK, you don't create ParseErrors as those are not ParseErrors, they are developer specific errors. I recommend looking at ParseAuthentication and ParseLDAP implementation first. Are you saying you need to do something completely different than what's already done? My brief look at Inside ParseLDAP, an error is created using the member wise initializer: Parse-Swift/Sources/ParseSwift/Authentication/3rd Party/ParseLDAP.swift Lines 150 to 161 in f3f2244
You can do the something for |
Sorry, this is a separate issue from my restoreAuthentication delegate issue I raised - though I ultimately need them both for my task. This is a custom auth provider that will live in my app code, not in the library, so there won't be a PR. This is to authenticate against an internal system we use at our company, so it wouldn't be appropriate to add to the library as it's hyper-specific to our use case. In the provider, one of the protocol methods is: func login(authData: [String: String],
options: API.Options = [],
callbackQueue: DispatchQueue = .main,
completion: @escaping (Result<AuthenticatedUser, ParseError>) -> Void) {
guard AuthenticationKeys.id.verifyMandatoryKeys(authData: authData) else {
callbackQueue.async {
completion(.failure(.init(code: .unknownError, message: "authData is missing required values.")))
}
return
}
AuthenticatedUser.login(Self.__type, authData: authData, options: options, callbackQueue: callbackQueue, completion: completion)
} However, that won't compile because I'm trying to create a ParseError for the completion handler in the case that the authData provided is incorrect. As the failure state in the handler requires a ParseError, I don't see another way I can mark this as a failure. Perhaps a custom ParseError case could be created for a non-parse error, and a public initializer would only create ParseErrors in that specific case with a custom error message? |
If I understand correctly, you are trying to conform to |
That sounds exactly correct. |
I will have to think about this some, but my initial thoughts are:
|
Out of the two, I would definitely prefer the second option. I think the first would be a pretty high barrier for entry if other people are looking to do the same thing. The only downside I see of the second option is that you'll need to do some extra work elsewhere in the SDK to verify that the errors you get back are indeed ParseErrors, now that the protocol doesn't explicitly require them to be so, and then it would be prudent to handle both scenarios - ParseErrors and generic Errors. |
You might get lucky with this as the SDK first attempts to decode the error from the server as a ParseError, if its not a ParseError, it turns the error into one. So it's possible it "may" not be a lot of work, but I'm guessing... |
Okay, let me finish my current work with the Easy Way (just using my init from this PR) and once I've verified that's working, I'll try swapping to a generic Error and make the changes for that, then I'll send in a separate PR for that portion and abandon this one. |
Thinking about this some more the internal authentication types lose some identity with If you are doing a custom conformance it might be best for you to just encode/decode ParseError to/from your custom created error (you can accomplish this using Swifts standard JSONEncoder/Decoder). That will allow you to add more error properties if you want and maintain the original ParseError. I don't think making the initializer public is the right solution either as developers shouldn't create errors and mask them as Parse Errors as that will lead people to believe they are real Parse Errors and encourage them to submit issues to this repo while they should be submitted to the specific repo that's using ParseSwift. I suggest you post your feedback before starting the implementation on the PR so you spend your time on the right solution. |
I see what you're saying but it still feels like quite a workaround. Plus ultimately we'd just be creating our own error, then serializing it, and using that payload to create a ParseError anyway and returning that. Just feels like a bunch of extra steps with the same end result: a ParseError that may be misleading as it technically originated outside of the Parse SDK. Let me think on it some more. |
True, but making If you are writing many custom auths, you can probably create a protocol that conforms to |
Closing this due to inactivity. Feel free to open if more questions. |
This is a very minor PR. Automatically generated initializers are only ever internal protection level, meaning they can't be used outside of the SDK. If a ParseError needs to be created from outside the library, like in a customer auth provider, a manual initializer must be provided.
This PR provides this initializer, which should match the generated initlizer. Code within the library should not need to change.