{"record":{"id":"db0bdfc65943c05f","repo":"t8y2/dbx","slug":"checked-length","errorCode":null,"errorMessage":"checked length","messagePattern":"checked length","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbx-core/src/db/dynamodb_driver.rs","lineNumber":287,"sourceCode":"                        .and_then(|object| object.get(\"$regex\"))\n                        .and_then(Value::as_str)\n                        .ok_or_else(|| format!(\"Unsupported DynamoDB $not condition for {field}\"))?;\n                    format!(\"NOT contains({path}, {})\", self.value(&Value::String(nested.to_string()))?)\n                }\n                other => return Err(format!(\"Unsupported DynamoDB filter operator: {other}\")),\n            };\n            clauses.push(clause);\n        }\n        if clauses.is_empty() {\n            return Err(format!(\"DynamoDB filter for {field} does not contain a condition\"));\n        }\n        Ok(clauses.join(\" AND \"))\n    }\n}\n\nfn join_condition_clauses(clauses: Vec<ConditionClause>, operator: &str, precedence: u8) -> ConditionClause {\n    if clauses.len() == 1 {\n        return clauses.into_iter().next().expect(\"checked length\");\n    }\n    let expression = clauses\n        .into_iter()\n        .map(\n            |clause| {\n                if clause.precedence < precedence {\n                    format!(\"({})\", clause.expression)\n                } else {\n                    clause.expression\n                }\n            },\n        )\n        .collect::<Vec<_>>()\n        .join(operator);\n    ConditionClause { expression, precedence }\n}\n\npub fn endpoint_url(config: &ConnectionConfig, host: &str, port: u16) -> String {","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/crates/dbx-core/src/db/dynamodb_driver.rs#L269-L305","documentation":"join_condition_clauses in the DynamoDB query builder collapses a list of ConditionClauses with an AND/OR operator. When exactly one clause is present it short-circuits with clauses.into_iter().next().expect(\"checked length\"); the expect is protected by the len()==1 check directly above and panics only if that guard is removed or reordered.","triggerScenarios":"Unreachable while `if clauses.len() == 1` precedes the into_iter().next(); a panic would indicate a refactor dropped the guard. Users never see this panic — with zero clauses callers skip joining, and with multiple clauses the code falls through to parenthesized combination.","commonSituations":"Builders constructing DynamoDB filter expressions from key conditions, filter expressions, or user query predicates; library maintainers refactoring condition_clause/join_condition_clauses; automated tests feeding single-condition queries (e.g. one equality key condition).","solutions":["Keep the len()==1 guard immediately before extraction; prefer `let Some(clause) = clauses.into_iter().next() else { ... }`.","Handle the empty-vec case explicitly (return a trivially-true clause or error) so the join never sees unexpected lengths.","Add a unit test joining 0, 1, and 2+ clauses to lock the behavior.","If panics are unacceptable in the query builder, switch join_condition_clauses to return Result<ConditionClause, String>."],"exampleFix":"// before\nif clauses.len() == 1 {\n    return clauses.into_iter().next().expect(\"checked length\");\n}\n// after\nif let Some(single) = clauses.into_iter().next() {\n    if matches!(clauses_len_hint, 1) { return single; }\n}\n// or simpler:\nif clauses.len() == 1 {\n    return match clauses.into_iter().next() { Some(c) => c, None => return trivially_true_clause() };\n}","handlingStrategy":"type-guard","validationCode":"// before joining condition clauses, handle degenerate lengths\nif clauses.is_empty() { return Ok(default_clause()); } // skip join entirely","typeGuard":"fn single_clause(clauses: Vec<ConditionClause>) -> Option<ConditionClause> {\n    if clauses.len() == 1 { clauses.into_iter().next() } else { None }\n}","tryCatchPattern":"if clauses.len() == 1 {\n    return match clauses.into_iter().next() {\n        Some(c) => c,\n        None => return default_clause(),\n    };\n}","preventionTips":["Handle 0-, 1-, and N-clause cases explicitly in the query builder.","Add unit tests covering each clause-count branch.","Use let-else or match instead of expect guarded by separate length checks.","Keep guard and extraction in the same expression scope so refactors cannot separate them."],"tags":["rust","panic","invariant","dynamodb","query-builder"],"backgroundTag":"empty-collection-unwrapping","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}