Skip to content

Commit

Permalink
propagate struct inner parsing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
stepansergeevitch committed Dec 13, 2024
1 parent 46a739b commit 5267b11
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ func parseStruct(structInnerFields string, val interface{}) (map[string]driver.V
}
for fieldName, fieldType := range fields {
if fieldValue, ok := structValue[fieldName]; ok {
res[fieldName], _ = parseValue(fieldType, fieldValue)
res[fieldName], err = parseValue(fieldType, fieldValue)
if err != nil {
return nil, ConstructNestedError("error during parsing struct field", err)
}
} else {
return nil, fmt.Errorf("field %s is missing in struct value %v", fieldName, structValue)
}
Expand Down
20 changes: 20 additions & 0 deletions rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,23 @@ func TestRowsNextSet(t *testing.T) {

assert(io.EOF, rows.Next(dest), t, "Next should return io.EOF if no data available anymore")
}

func TestRowsNextStructError(t *testing.T) {
rowsJson := `{
"query":{"query_id":"16FF2A0300ECA753"},
"meta":[{"name":"struct_col","type":"struct(a int, s struct(b datetime))"}],
"data":[[{"a": 1, "s": {"b": "invalid"}}]],
"rows":1,
"statistics":{}
}`
var response QueryResponse
if err := json.Unmarshal([]byte(rowsJson), &response); err != nil {
panic(err)
}

rows := &fireboltRows{[]QueryResponse{response}, 0, 0}
var dest = make([]driver.Value, 1)
if err := rows.Next(dest); err == nil {
t.Errorf("Next should return an error")
}
}

0 comments on commit 5267b11

Please sign in to comment.