{"record":{"id":"db6b75c67f088c02","repo":"risingwavelabs/risingwave","slug":"anyhow-err","errorCode":null,"errorMessage":"anyhow!(err)","messagePattern":"anyhow!\\(err\\)","errorType":"exception","errorClass":"MetaError","httpStatus":null,"severity":"error","filePath":"src/meta/src/controller/mod.rs","lineNumber":55,"sourceCode":"use crate::{MetaError, MetaResult, MetaStoreBackend};\n\npub mod catalog;\npub mod cluster;\npub mod fragment;\npub mod id;\npub mod rename;\npub mod scale;\npub mod session_params;\npub mod streaming_job;\npub mod system_param;\npub mod user;\npub mod utils;\n\n// todo: refine the error transform.\nimpl From<sea_orm::DbErr> for MetaError {\n    fn from(err: sea_orm::DbErr) -> Self {\n        if let Some(err) = err.sql_err() {\n            return anyhow!(err).into();\n        }\n        anyhow!(err).into()\n    }\n}\n\n#[derive(Clone)]\npub struct SqlMetaStore {\n    pub conn: DatabaseConnection,\n    pub endpoint: String,\n}\n\nimpl SqlMetaStore {\n    /// Connect to the SQL meta store based on the given configuration.\n    pub async fn connect(backend: MetaStoreBackend) -> MetaResult<Self> {\n        const MAX_DURATION: Duration = Duration::new(u64::MAX / 4, 0);\n\n        #[easy_ext::ext]\n        impl ConnectOptions {","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/meta/src/controller/mod.rs#L37-L73","documentation":"Part of the From<sea_orm::DbErr> for MetaError conversion: when the DbErr is a SQL-level error (constraint violation, syntax, etc., exposed via sql_err()), it is re-wrapped with anyhow! into MetaError. There is even a `// todo: refine the error transform` note — the wrap loses structure.","triggerScenarios":"Any meta-store operation through sea_orm whose query fails at the SQL layer (unique constraint, foreign key, SQL syntax, locked table) is converted to MetaError via this From impl.","commonSituations":"Duplicate primary key on insert during concurrent DDL, schema drift between code and the SQL meta store, SQLite/Postgres lock contention.","solutions":["Inspect the inner SQL error message in MetaError to see the actual constraint/query that failed.","Resolve the underlying DB condition (duplicate key, missing table/column, lock) rather than retrying blindly.","Consider matching on the concrete sql_err variant upstream for better handling (aligns with the code's own 'refine the error transform' todo)."],"exampleFix":"// before\nreturn anyhow!(err).into();\n// after\nreturn MetaError::internal(format!(\"meta store sql error: {err}\")); // preserve variant info","handlingStrategy":"try-catch","validationCode":"// Check constraint preconditions before insert, e.g. duplicate-key probe\nif txn.exists_duplicate(job).await? { bail!(\"duplicate meta record\"); }","typeGuard":null,"tryCatchPattern":"match res {\n    Err(e) if e.to_string().contains(\"constraint\") => /* handle conflict */,\n    Err(e) => return Err(e),\n    Ok(v) => v,\n}","preventionTips":["Pre-validate uniqueness/FKs before meta writes","Keep meta schema migrations in sync with code version","Log the inner sea_orm error before it is generically wrapped","Retry only on transient connection-class errors"],"tags":["database","sea-orm","sql","error-transform"],"backgroundTag":"database-query-failed","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}