MongoDB: panic(err) in production code path in write.go
File: plugins/destination/mongodb/client/write.go
Problem: panic(err) is used instead of returning errors when json.Unmarshal fails in transformArr. In a production system, this means any malformed JSON data in a record column will crash the entire process instead of being handled gracefully (e.g., skipping the row, logging an error, or returning the error up the call chain to be retried).
Current code (multi-location):
case *types.JSONArray:
var val any
if err := json.Unmarshal([]byte(a.ValueStr(i)), &val); err != nil {
panic(err) // crashes the process
}
case *array.Struct:
var val any
if err := json.Unmarshal([]byte(a.ValueStr(i)), &val); err != nil {
panic(err) // crashes the process
}
Additionally, transformArr, transformRecord, and transformRecords all return []any without an error return — so even if the panics were replaced, there was no way to propagate errors. The function signatures needed to be changed to ([]any, error).
Fix: Replace panic(err) with return nil, err and update all callers to propagate the error.
Reproduction
- Configure a MongoDB destination plugin.
- Set up a source that produces records with an invalid JSON value in a column typed as
JSONArray or Struct (e.g., a malformed JSON string that json.Unmarshal can't parse).
- Run
cloudquery sync — the process crashes with a panic instead of reporting an error and continuing.
Example of a record that triggers this:
Column type: JSONArray
Value: "{invalid json without proper structure"
MongoDB: panic(err) in production code path in write.go
File:
plugins/destination/mongodb/client/write.goProblem:
panic(err)is used instead of returning errors whenjson.Unmarshalfails intransformArr. In a production system, this means any malformed JSON data in a record column will crash the entire process instead of being handled gracefully (e.g., skipping the row, logging an error, or returning the error up the call chain to be retried).Current code (multi-location):
Additionally,
transformArr,transformRecord, andtransformRecordsall return[]anywithout an error return — so even if the panics were replaced, there was no way to propagate errors. The function signatures needed to be changed to([]any, error).Fix: Replace
panic(err)withreturn nil, errand update all callers to propagate the error.Reproduction
JSONArrayorStruct(e.g., a malformed JSON string thatjson.Unmarshalcan't parse).cloudquery sync— the process crashes with a panic instead of reporting an error and continuing.Example of a record that triggers this: