diff --git a/cmd/restic/global.go b/cmd/restic/global.go index 6920caa8d..cc24b74c2 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -280,7 +280,7 @@ func readPassword(in io.Reader) (password string, err error) { sc := bufio.NewScanner(in) sc.Scan() - return sc.Text(), errors.Wrap(err, "Scan") + return sc.Text(), errors.WithStack(sc.Err()) } // readPasswordTerminal reads the password from the given reader which must be a diff --git a/cmd/restic/global_test.go b/cmd/restic/global_test.go index 4f5c29e9a..b43fdd1f3 100644 --- a/cmd/restic/global_test.go +++ b/cmd/restic/global_test.go @@ -5,6 +5,7 @@ import ( "path/filepath" "testing" + "github.com/restic/restic/internal/errors" rtest "github.com/restic/restic/internal/test" ) @@ -22,6 +23,16 @@ func Test_PrintFunctionsRespectsGlobalStdout(t *testing.T) { } } +type errorReader struct{ err error } + +func (r *errorReader) Read([]byte) (int, error) { return 0, r.err } + +func TestReadPassword(t *testing.T) { + want := errors.New("foo") + _, err := readPassword(&errorReader{want}) + rtest.Assert(t, errors.Is(err, want), "wrong error %v", err) +} + func TestReadRepo(t *testing.T) { tempDir := rtest.TempDir(t)