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