mirror of
https://github.com/restic/restic.git
synced 2026-08-03 04:32:17 +00:00
panic if hash returns an error
Add a sanity check that the interface contract is honoured.
This commit is contained in:
@@ -56,7 +56,10 @@ func NewByteReader(buf []byte, hasher hash.Hash) *ByteReader {
|
||||
var hash []byte
|
||||
if hasher != nil {
|
||||
// must never fail according to interface
|
||||
_, _ = hasher.Write(buf)
|
||||
_, err := hasher.Write(buf)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
hash = hasher.Sum(nil)
|
||||
}
|
||||
return &ByteReader{
|
||||
|
||||
@@ -54,7 +54,10 @@ func TestFileReader(t *testing.T) {
|
||||
var hash []byte
|
||||
if hasher != nil {
|
||||
// must never fail according to interface
|
||||
_, _ = hasher.Write(buf)
|
||||
_, err := hasher.Write(buf)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
hash = hasher.Sum(nil)
|
||||
}
|
||||
rd, err := NewFileReader(f, hash)
|
||||
|
||||
Reference in New Issue
Block a user