{"record":{"id":"5879a448a47d98d1","repo":"t8y2/dbx","slug":"required-table-field","errorCode":null,"errorMessage":"required table field","messagePattern":"required table field","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbx-core/src/db/dynamodb_driver.rs","lineNumber":434,"sourceCode":"    let mut current_name: Option<String> = None;\n    let mut current_value = String::new();\n    for line in lines {\n        if let Some((name, value)) = dynamodb_statement_field(line) {\n            finish_dynamodb_statement_field(&mut fields, current_name.take(), &mut current_value)?;\n            current_name = Some(name.to_string());\n            current_value.push_str(value.trim_start());\n        } else if current_name.is_some() {\n            if !current_value.is_empty() {\n                current_value.push('\\n');\n            }\n            current_value.push_str(line);\n        } else if !line.trim().is_empty() {\n            return Err(format!(\"Invalid DynamoDB statement line: {line}\"));\n        }\n    }\n    finish_dynamodb_statement_field(&mut fields, current_name.take(), &mut current_value)?;\n\n    let table = take_dynamodb_string_field(&mut fields, \"table\", true)?.expect(\"required table field\");\n    let limit = take_dynamodb_integer_field(&mut fields, \"limit\")?;\n    if limit.is_some_and(|value| value <= 0) {\n        return Err(\"DynamoDB statement limit must be greater than zero\".to_string());\n    }\n    let filter = take_dynamodb_object_field(&mut fields, \"filter\")?;\n    let sort = take_dynamodb_object_field(&mut fields, \"sort\")?;\n    let cursor = take_dynamodb_string_field(&mut fields, \"cursor\", false)?;\n    let key = take_dynamodb_object_field(&mut fields, \"key\")?;\n    let item = take_dynamodb_object_field(&mut fields, \"item\")?;\n    if !fields.is_empty() {\n        return Err(format!(\"Unsupported DynamoDB statement field: {}\", fields.keys().next().unwrap()));\n    }\n\n    match operation {\n        DynamoDbStatementOperation::Read => {\n            if key.is_some() || item.is_some() {\n                return Err(\"DynamoDB read statements do not accept key or item fields\".to_string());\n            }","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/crates/dbx-core/src/db/dynamodb_driver.rs#L416-L452","documentation":"Panic from `Option::expect` on the result of take_dynamodb_string_field(\"table\", true). The helper is asked to require the table field (required=true) but still returns Option, so the code asserts it with expect. A panic here means the field lookup logic failed to enforce its own required flag — an internal bug, since a genuinely missing table should already have produced an Err from take_dynamodb_string_field.","triggerScenarios":"Parsing a DynamoDB statement text without a `table` field where take_dynamodb_string_field somehow returns Ok(None) despite required=true — i.e. a bug in the field-taking helper's required handling rather than normal parser input.","commonSituations":"Changes to take_dynamodb_string_field altering its required-field semantics; regression where required=true no longer maps to an Err; fuzzer-generated inputs exploring the parser.","solutions":["Change take_dynamodb_string_field so required=true returns Result<String, String> directly and drop the expect","Fix the helper to return Err(\"missing required field: table\") when required and absent","Add tests for statements missing the table field to confirm a clean parse error","Audit all call sites of take_dynamodb_*_field(..., true) for the same expect pattern"],"exampleFix":"// before\nlet table = take_dynamodb_string_field(&mut fields, \"table\", true)?.expect(\"required table field\");\n// after\nlet table = take_dynamodb_string_field(&mut fields, \"table\", true)?\n    .ok_or_else(|| \"DynamoDB statement requires a table field\".to_string())?;","handlingStrategy":"validation","validationCode":"let has_table = statement_text.lines()\n    .any(|l| l.trim_start().to_lowercase().starts_with(\"table\"));\nif !has_table {\n    return Err(\"DynamoDB statement text must include a 'table' field\".into());\n}","typeGuard":null,"tryCatchPattern":"match parse_dynamodb_statement(text) {\n    Ok(stmt) => stmt,\n    Err(e) => return Err(format!(\"invalid statement: {e}\")),\n}","preventionTips":["Always include a table field in DynamoDB statement text","Validate statement text before parsing in user-facing flows","Keep required-field handling inside take_dynamodb_*_field helpers and unit-test it"],"tags":["rust","dynamodb","parser","panic"],"backgroundTag":"missing-required-field","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"}