Skip to content

Commit 2b9e1c4

Browse files
committed
allow hscan to continue past first failure
1 parent 4cb9d14 commit 2b9e1c4

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

internal/hscan/hscan.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ func Scan(dst interface{}, keys []interface{}, vals []interface{}) error {
7777
return err
7878
}
7979

80+
scanErrors := []error{}
81+
8082
// Iterate through the (key, value) sequence.
8183
for i := 0; i < len(vals); i++ {
8284
key, ok := keys[i].(string)
@@ -90,10 +92,14 @@ func Scan(dst interface{}, keys []interface{}, vals []interface{}) error {
9092
}
9193

9294
if err := strct.Scan(key, val); err != nil {
93-
return err
95+
scanErrors = append(scanErrors, err)
9496
}
9597
}
9698

99+
if len(scanErrors) > 0 {
100+
return fmt.Errorf("scan errors: %v", scanErrors)
101+
}
102+
97103
return nil
98104
}
99105

internal/hscan/hscan_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,21 @@ var _ = Describe("Scan", func() {
175175
Expect(Scan(&d, i{"bool"}, i{""})).To(HaveOccurred())
176176
Expect(Scan(&d, i{"bool"}, i{"123"})).To(HaveOccurred())
177177
})
178+
179+
It("does not stop scanning on first failure", func() {
180+
var d data
181+
182+
keys := i{"bool", "string", "int"}
183+
vals := i{"-1", "foobar", "123"}
184+
185+
err := Scan(&d, keys, vals)
186+
Expect(err).To(HaveOccurred())
187+
188+
Expect(d).To(Equal(data{
189+
Bool: false,
190+
String: "foobar",
191+
Int: 123,
192+
}))
193+
194+
})
178195
})

0 commit comments

Comments
 (0)