2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-23 11:28:54 +00:00

Merge pull request #2857 from MichaelEischer/incomplete-backup-error

Don't print a stacktrace if some files could not be read
This commit is contained in:
rawtaz 2020-07-29 00:06:25 +02:00 committed by GitHub
commit 48f97f3567
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 5 deletions

View File

@ -98,8 +98,8 @@ type BackupOptions struct {
var backupOptions BackupOptions var backupOptions BackupOptions
// Error sentinel for invalid source data // ErrInvalidSourceData is used to report an incomplete backup
var InvalidSourceData = errors.New("Failed to read all source data during backup.") var ErrInvalidSourceData = errors.New("failed to read all source data during backup")
func init() { func init() {
cmdRoot.AddCommand(cmdBackup) cmdRoot.AddCommand(cmdBackup)
@ -601,7 +601,7 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, term *termstatus.Termina
p.P("snapshot %s saved\n", id.Str()) p.P("snapshot %s saved\n", id.Str())
} }
if !success { if !success {
return InvalidSourceData return ErrInvalidSourceData
} }
// Return error if any // Return error if any

View File

@ -515,7 +515,7 @@ func TestBackupErrors(t *testing.T) {
gopts.stderr = ioutil.Discard gopts.stderr = ioutil.Discard
err := testRunBackupAssumeFailure(t, filepath.Dir(env.testdata), []string{"testdata"}, opts, gopts) err := testRunBackupAssumeFailure(t, filepath.Dir(env.testdata), []string{"testdata"}, opts, gopts)
rtest.Assert(t, err != nil, "Assumed failure, but no error occured.") rtest.Assert(t, err != nil, "Assumed failure, but no error occured.")
rtest.Assert(t, err == InvalidSourceData, "Wrong error returned") rtest.Assert(t, err == ErrInvalidSourceData, "Wrong error returned")
snapshotIDs := testRunList(t, "snapshots", env.gopts) snapshotIDs := testRunList(t, "snapshots", env.gopts)
rtest.Assert(t, len(snapshotIDs) == 1, rtest.Assert(t, len(snapshotIDs) == 1,
"expected one snapshot, got %v", snapshotIDs) "expected one snapshot, got %v", snapshotIDs)

View File

@ -88,6 +88,8 @@ func main() {
switch { switch {
case restic.IsAlreadyLocked(errors.Cause(err)): case restic.IsAlreadyLocked(errors.Cause(err)):
fmt.Fprintf(os.Stderr, "%v\nthe `unlock` command can be used to remove stale locks\n", err) fmt.Fprintf(os.Stderr, "%v\nthe `unlock` command can be used to remove stale locks\n", err)
case err == ErrInvalidSourceData:
fmt.Fprintf(os.Stderr, "Warning: %v\n", err)
case errors.IsFatal(errors.Cause(err)): case errors.IsFatal(errors.Cause(err)):
fmt.Fprintf(os.Stderr, "%v\n", err) fmt.Fprintf(os.Stderr, "%v\n", err)
case err != nil: case err != nil:
@ -106,7 +108,7 @@ func main() {
switch err { switch err {
case nil: case nil:
exitCode = 0 exitCode = 0
case InvalidSourceData: case ErrInvalidSourceData:
exitCode = 3 exitCode = 3
default: default:
exitCode = 1 exitCode = 1