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

Improve error messages for underlying NSErrors and Swift errors #101

Conversation

interstateone
Copy link
Contributor

@interstateone interstateone commented Aug 26, 2020

LegibleError provides less valuable strings for NSErrors because it intentionally doesn't return their localized descriptions when they start with "The operation couldn’t be completed." This results in error messages like “ The operation couldn’t be completed. (NSPOSIXErrorDomain.28)” instead of “ The operation couldn’t be completed. No space left on device”. I think users would find the latter more valuable.

For NSErrors, I'm not sure if we should be doing something different in order to get better behaviour when using LegibleError. Setting NSLocalizedFailureErrorKey everywhere might be an option because that replaces "The operation couldn't be completed" at the start of the error’s localized description.

For Swift errors, LegibleDescription can provide much better errors, for example with DecodingError.

This PR began as a quick fix for #79 but I’m going to leave it as a draft because I’m not confident that the current change is better in all cases (see also #52 and #96), and it’s an opportunity to come up with more wholistic error modelling.

It may help to better define what we want to show to the user. This is a developer tool that can fail in the middle of a long-running process. We want user-friendly error messages so that they can attempt to recover on their own. I think we can err on the side of showing more technical information, like that something failed because of a JSON decoding error, because users will be familiar with this process. This should be in addition to user-friendly messages, though, not in place of them. For example, we should display a failure reason and an OSStatus code instead of only the code. It can also be valuable for bug reporting purposes to print the description (which is more like a debug description, as opposed to localized description) of the error, and this should also be in addition to the localized description.

While it seems valuable for errors without localized descriptions, it provides worse strings for NSErrors because it intentionally doesn't return their localized descriptions when they start with "The operation couldn’t be completed." Maybe this is due to the state of Foundation on Linux. In any case, I don't think this is providing as much value as I thought it would, so we'll revert to using the localized descriptions.

Fixes XcodesOrg#79.
@interstateone interstateone marked this pull request as draft August 26, 2020 06:00
@interstateone interstateone changed the title Remove LegibleError and use localizedDescription Improve error messages for underlying NSErrors and Swift errors Aug 26, 2020
Base automatically changed from master to main January 20, 2021 23:46
@interstateone interstateone deleted the use-nserror-localized-description branch February 3, 2021 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant