{"record":{"id":"c5655fc1bae20105","repo":"risingwavelabs/risingwave","slug":"sinkerror-config-anyhow-e","errorCode":null,"errorMessage":"SinkError::Config(anyhow!(e))","messagePattern":"SinkError::Config\\(anyhow!\\(e\\)\\)","errorType":"validation","errorClass":"SinkError::Config","httpStatus":null,"severity":"error","filePath":"src/connector/src/sink/mongodb.rs","lineNumber":169,"sourceCode":"    pub bulk_write_max_entries: usize,\n\n    #[serde(flatten)]\n    pub unknown_fields: std::collections::HashMap<String, String>,\n}\n\ncrate::impl_sink_unknown_fields!(MongodbConfig);\n\nimpl EnforceSecret for MongodbConfig {\n    fn enforce_one(prop: &str) -> crate::error::ConnectorResult<()> {\n        MongodbCommon::enforce_one(prop)\n    }\n}\n\nimpl MongodbConfig {\n    pub fn from_btreemap(properties: BTreeMap<String, String>) -> crate::sink::Result<Self> {\n        let config =\n            serde_json::from_value::<MongodbConfig>(serde_json::to_value(properties).unwrap())\n                .map_err(|e| SinkError::Config(anyhow!(e)))?;\n        if config.r#type != SINK_TYPE_APPEND_ONLY && config.r#type != SINK_TYPE_UPSERT {\n            return Err(SinkError::Config(anyhow!(\n                \"`{}` must be {}, or {}\",\n                SINK_TYPE_OPTION,\n                SINK_TYPE_APPEND_ONLY,\n                SINK_TYPE_UPSERT\n            )));\n        }\n        Ok(config)\n    }\n}\n\n/// An async-drop style `Guard` for `mongodb::Client`. Use this guard to hold a client,\n/// the `client::shutdown` is called in an async manner when the guard is dropped.\n/// Please be aware this is a \"best effort\" style shutdown, which may not be successful if the\n/// tokio runtime is in the process of terminating. However, the server-side resources will be\n/// cleaned up eventually due to the session expiration.\n/// see [this issue](https://github.com/mongodb/mongo-rust-driver/issues/719) for more information","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/connector/src/sink/mongodb.rs#L151-L187","documentation":"MongodbConfig::from_btreemap parses the sink's user properties into a MongodbConfig via a serde_json round-trip. If deserialization fails (missing required fields like 'url', or fields with wrong types), the serde error is wrapped in SinkError::Config.","triggerScenarios":"serde_json::from_value::<MongodbConfig> fails: the WITH properties map lacks required fields (e.g. 'url' or 'type') or a property's value type doesn't match the config struct (e.g. url is not a string).","commonSituations":"Typo in a required option name in the CREATE SINK WITH (...) clause, omitting 'url' or 'type' entirely, passing numeric/boolean values where strings are expected, or extra unknown properties when deny_unknown_fields is active.","solutions":["Ensure 'url' (mongodb://... connection string) and 'type' are present in the WITH options.","Check for typos in property names against the MongodbConfig struct fields.","Quote string values in the DDL so serde receives strings, not numbers/booleans.","Validate the connection string format: mongodb://user:pass@host:port/db."],"exampleFix":"// before\nCREATE SINK s FROM mv WITH (\n  connector = 'mongodb',\n  endpoint = 'mongodb://localhost:27017'  -- unknown/wrong field\n);\n// after\nCREATE SINK s FROM mv WITH (\n  connector = 'mongodb',\n  url = 'mongodb://localhost:27017',\n  type = 'append_only'\n);","handlingStrategy":"validation","validationCode":"-- validate WITH options before CREATE SINK\n-- required: connector='mongodb', url (string), type in ('append_only','upsert')\nSELECT * FROM rw_catalog.rw_databases; -- or dry-run the config locally\n","typeGuard":null,"tryCatchPattern":"// catch config parse failures at sink creation time and show the serde message\nmatch MongodbConfig::from_btreemap(props) {\n    Ok(cfg) => proceed(cfg),\n    Err(e) => return Err(format!(\"invalid mongodb sink options: {e}\")),\n}","preventionTips":["Keep a copy of the accepted WITH options per connector version.","Quote all property values as strings in the DDL.","Double-check required keys ('url', 'type') before submitting DDL.","Test the config with a minimal sink against a local MongoDB first."],"tags":["rust","mongodb","config","serde"],"backgroundTag":"schema-validation-failed","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}