Improve error messages for underlying NSErrors and Swift errors #101
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.