Skip to content

Commit

Permalink
backport fix to 8.11.6
Browse files Browse the repository at this point in the history
  • Loading branch information
cpoole committed Oct 21, 2022
1 parent 52af8ba commit 957d362
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/hscan/hscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ func Scan(dst interface{}, keys []interface{}, vals []interface{}) error {
return err
}

scanErrors := []error{}

// Iterate through the (key, value) sequence.
for i := 0; i < len(vals); i++ {
key, ok := keys[i].(string)
Expand All @@ -90,10 +92,14 @@ func Scan(dst interface{}, keys []interface{}, vals []interface{}) error {
}

if err := strct.Scan(key, val); err != nil {
return err
scanErrors = append(scanErrors, err)
}
}

if len(scanErrors) > 0 {
return fmt.Errorf("scan errors: %v", scanErrors)
}

return nil
}

Expand Down
18 changes: 18 additions & 0 deletions internal/hscan/hscan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,22 @@ var _ = Describe("Scan", func() {
Expect(Scan(&d, i{"bool"}, i{""})).To(HaveOccurred())
Expect(Scan(&d, i{"bool"}, i{"123"})).To(HaveOccurred())
})

It("does not stop scanning on first failure", func() {
var d data

keys := i{"bool", "string", "int", "uint8"}
vals := i{"-1", "foobar", "123", "12345"}

err := Scan(&d, keys, vals)
Expect(err).To(HaveOccurred())

Expect(d).To(Equal(data{
Bool: false,
String: "foobar",
Int: 123,
Uint8: 0,
}))

})
})

0 comments on commit 957d362

Please sign in to comment.