@@ -67,6 +67,9 @@ func Struct(dst interface{}) (StructValue, error) {
67
67
68
68
// Scan scans the results from a key-value Redis map result set to a destination struct.
69
69
// The Redis keys are matched to the struct's field with the `redis` tag.
70
+ // This method will attempt to unmarshal each field and will return an error if any of the
71
+ // fields cannot be unmarshalled. The destination struct will have the failed fields set to
72
+ // their zero value.
70
73
func Scan (dst interface {}, keys []interface {}, vals []interface {}) error {
71
74
if len (keys ) != len (vals ) {
72
75
return errors .New ("args should have the same number of keys and vals" )
@@ -77,6 +80,8 @@ func Scan(dst interface{}, keys []interface{}, vals []interface{}) error {
77
80
return err
78
81
}
79
82
83
+ scanErrors := []error {}
84
+
80
85
// Iterate through the (key, value) sequence.
81
86
for i := 0 ; i < len (vals ); i ++ {
82
87
key , ok := keys [i ].(string )
@@ -90,10 +95,14 @@ func Scan(dst interface{}, keys []interface{}, vals []interface{}) error {
90
95
}
91
96
92
97
if err := strct .Scan (key , val ); err != nil {
93
- return err
98
+ scanErrors = append ( scanErrors , err )
94
99
}
95
100
}
96
101
102
+ if len (scanErrors ) > 0 {
103
+ return fmt .Errorf ("scan errors: %v" , scanErrors )
104
+ }
105
+
97
106
return nil
98
107
}
99
108
0 commit comments