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.
NOTE: This is a LARGE PR but it only does one thing. If you may plan to accept it, you should do before you add a lot of new code or it will just be too hard to resolve the conflicts. HOWEVER, this PR changes the API so to follow SemVer I think you would need to bump the major version number.
Purpose
This PR replaces finds almost all places where an error is returned by a function — but the Mutagen code just ignores the error — and it adds logging in case an error is returned.
I discovered these issues while I was making changes for my own needs on my fork for #505. My IDE kept complaining about unhandled errors, so I decided to fix them and move to a separate PR. As it turned out, fixing them was quite the rabbit hole, but I did so because I know having all unhandled errors logged will make for more robust software and potentially reveal edge-case bugs in the code you did not even realize where there.
Serendipitously DoltHub published a blog post entitled "What's the best Static Analysis tool for Golang?" that starts with an example of an unhandled error as justification for why handling all errors is so important. I say "serendipitously" because it was published after I wrote the code for this PR.
What the PR Changed
The PR adds a package named
must
which includes functions for most of the places where errors were being ignored, such asClose()
,Shudown()
, etc. Then is replaces the code that looks like this:With code that looks like this:
In order to ensure a
logger
was always available, this PR adds:a. A
logger
property to every struct that has a method where unhandled errors occurred, orb. A
logger
parameter for every package function where unhandled errors occurred, andc. Ensured those properties were set and parameters were passed in all cases.
In the very few cases that use interfaces I decided to handle the error manually so as not to modify the interface.
In one case I could not find a reasonable way to get a
logger
so I just left aTODO
comment.Summary
I really hope you will consider accepting this. It was a few days of work to both find and fix all the case and to them get all the CI tests to pass. If you do, I think it will help you make
Mutagen
even more robust moving forward.