diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index 77b0925fe..f410fb1fd 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -98,8 +98,8 @@ type BackupOptions struct { var backupOptions BackupOptions -// Error sentinel for invalid source data -var InvalidSourceData = errors.New("Failed to read all source data during backup.") +// ErrInvalidSourceData is used to report an incomplete backup +var ErrInvalidSourceData = errors.New("failed to read all source data during backup") func init() { cmdRoot.AddCommand(cmdBackup) @@ -601,7 +601,7 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, term *termstatus.Termina p.P("snapshot %s saved\n", id.Str()) } if !success { - return InvalidSourceData + return ErrInvalidSourceData } // Return error if any diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index 5ffb5ee22..5b3ca6d95 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -515,7 +515,7 @@ func TestBackupErrors(t *testing.T) { gopts.stderr = ioutil.Discard 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 == InvalidSourceData, "Wrong error returned") + rtest.Assert(t, err == ErrInvalidSourceData, "Wrong error returned") snapshotIDs := testRunList(t, "snapshots", env.gopts) rtest.Assert(t, len(snapshotIDs) == 1, "expected one snapshot, got %v", snapshotIDs) diff --git a/cmd/restic/main.go b/cmd/restic/main.go index 63c4dbe41..2f553c9cc 100644 --- a/cmd/restic/main.go +++ b/cmd/restic/main.go @@ -88,6 +88,8 @@ func main() { switch { case restic.IsAlreadyLocked(errors.Cause(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)): fmt.Fprintf(os.Stderr, "%v\n", err) case err != nil: @@ -106,7 +108,7 @@ func main() { switch err { case nil: exitCode = 0 - case InvalidSourceData: + case ErrInvalidSourceData: exitCode = 3 default: exitCode = 1