Merge pull request #4845 from greatroar/errors

Fix error handling bug + clean up error messages
This commit is contained in:
Michael Eischer
2024-06-07 17:07:07 +00:00
committed by GitHub
3 changed files with 20 additions and 8 deletions
+1 -1
View File
@@ -287,7 +287,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
+11
View File
@@ -7,6 +7,7 @@ import (
"strings"
"testing"
"github.com/restic/restic/internal/errors"
rtest "github.com/restic/restic/internal/test"
)
@@ -24,6 +25,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)