Don't print a stacktrace if some files could not be read

This commit is contained in:
Michael Eischer 2020-07-28 22:57:40 +02:00
parent be54ceff66
commit 3ce9893e0b
3 changed files with 7 additions and 5 deletions

View file

@ -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

View file

@ -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)

View file

@ -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