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

find command: don't abort on tree load errors #2231

Merged
merged 1 commit into from Apr 14, 2019
Merged

Conversation

cdhowie
Copy link
Contributor

@cdhowie cdhowie commented Mar 30, 2019

What is the purpose of this change? What does it change?

As per #2224, this changes find not to abort when a tree can't be found. Instead, the tree ID and referent snapshot ID are displayed. This makes it easier to recover a broken repository by forgetting any snapshots that refer to missing objects.

Closes #2224

Was the change discussed in an issue or in the forum before?

A few times on the forum:

Checklist

  • I have read the Contribution Guidelines
  • I have added tests for all changes in this PR
  • I have added documentation for the changes (in the manual)
  • There's a new file in changelog/unreleased/ that describes the changes for our users (template here)
  • I have run gofmt on the code in all commits
  • All commit messages are formatted in the same style as the other commits in the repo
  • I'm done, this Pull Request is ready for review

Comments on above:

  • There's a few cursory tests for find, but not ones that use many of the options. This is also a particularly hard change to construct a test repository for, at least automatically.
  • It was not documented before that find stops on a tree load error, so there aren't really any sensible changes to be made.

@codecov-io
Copy link

codecov-io commented Mar 30, 2019

Codecov Report

Merging #2231 into master will decrease coverage by 4.27%.
The diff coverage is 14.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2231      +/-   ##
==========================================
- Coverage   50.92%   46.65%   -4.28%     
==========================================
  Files         176      176              
  Lines       14265    14269       +4     
==========================================
- Hits         7265     6657     -608     
- Misses       5942     6611     +669     
+ Partials     1058     1001      -57
Impacted Files Coverage Δ
cmd/restic/cmd_find.go 36.15% <14.28%> (-0.48%) ⬇️
internal/backend/b2/b2.go 0% <0%> (-80.69%) ⬇️
internal/backend/swift/swift.go 0% <0%> (-78.83%) ⬇️
internal/backend/gs/gs.go 0% <0%> (-74%) ⬇️
internal/backend/azure/azure.go 0% <0%> (-69.46%) ⬇️
internal/backend/swift/config.go 34.69% <0%> (-57.15%) ⬇️
internal/checker/checker.go 64.54% <0%> (-3.87%) ⬇️
internal/archiver/blob_saver.go 95.06% <0%> (+2.46%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 870e758...36f22a0. Read the comment docs.

Copy link
Member

@fd0 fd0 left a comment

Choose a reason for hiding this comment

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

Thank you very much for your contribution! The code looks great, just a minor thing: I'd like to suggest using Warnf() instead of Printf(), so the warning is printed to stderr instead of stdout. What do you think?

return false, err
debug.Log("Error loading tree %v: %v", parentTreeID, err)

Printf("Unable to load tree %s\n ... which belongs to snapshot %s.\n", parentTreeID, sn.ID())
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Printf("Unable to load tree %s\n ... which belongs to snapshot %s.\n", parentTreeID, sn.ID())
Warnf("Unable to load tree %s\n ... which belongs to snapshot %s.\n", parentTreeID, sn.ID())

return false, err
debug.Log("Error loading tree %v: %v", parentTreeID, err)

Printf("Unable to load tree %s\n ... which belongs to snapshot %s.\n", parentTreeID, sn.ID())
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Printf("Unable to load tree %s\n ... which belongs to snapshot %s.\n", parentTreeID, sn.ID())
Warnf("Unable to load tree %s\n ... which belongs to snapshot %s.\n", parentTreeID, sn.ID())

@cdhowie
Copy link
Contributor Author

cdhowie commented Apr 13, 2019

I think this one could go either way. Here is my take on it.

The point of having stdout and stderr is so that output can be separated from diagnostic information, particularly in the case where the output needs to be read by another program.

I'm not sure how find works with --json (I admittedly did not test it before submitting the PR). If it supports that, then we have to decide if this is diagnostic information for humans (it should go to stderr) or it's relevant results from the operation (it should be added to the JSON structure).

Not running in JSON mode, the same question applies: are these errors considered important output from the requested operation, or a diagnostic that should be relegated to a side-channel?

IMO, if you're running find with --blob or --tree then your repository has problems and you're trying to figure out why. In that case, I think that these warnings are directly related to the purpose of the command: someone is asking "what is wrong with my repository?" and therefore they should be part of the output.

But I will not argue if you'd rather have them on stderr because I think a case can be made for both options.

@fd0
Copy link
Member

fd0 commented Apr 14, 2019

You made a good point and I agree, let's leave it on stdout for now. Thanks!

@fd0 fd0 merged commit 36f22a0 into restic:master Apr 14, 2019
fd0 added a commit that referenced this pull request Apr 14, 2019
find command: don't abort on tree load errors
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.

The find command should not fail when objects are missing from the repository
3 participants