{"record":{"id":"034f8c3b28a66262","repo":"databendlabs/databend","slug":"expected-to-have-terminated-string-literal-after-q-034f8c","errorCode":null,"errorMessage":"Expected to have terminated string literal after quota ', while consumed buf: {:?}","messagePattern":"Expected to have terminated string literal after quota ', while consumed buf: (.+?)","errorType":"validation","errorClass":"InvalidData","httpStatus":null,"severity":"error","filePath":"src/common/io/src/cursor_ext/cursor_read_string_ext.rs","lineNumber":181,"sourceCode":"                    b'\\'' => {\n                        check_pos(pos + 1, positions)?;\n                        buf.push(b'\\'');\n                    }\n                    b'\\\\' => {\n                        check_pos(pos + 1, positions)?;\n                        buf.push(b'\\\\');\n                    }\n                    _ => {\n                        buf.push(b'\\\\');\n                        buf.push(c);\n                    }\n                }\n            } else {\n                break;\n            }\n            start = self.position() as usize;\n        }\n        Err(std::io::Error::new(\n            ErrorKind::InvalidData,\n            format!(\n                \"Expected to have terminated string literal after quota \\', while consumed buf: {:?}\",\n                buf\n            ),\n        ))\n    }\n}\n\n// Check that the pre-calculated position is correct.\nfn check_pos(curr_pos: usize, positions: &mut VecDeque<usize>) -> Result<()> {\n    if let Some(pos) = positions.pop_front()\n        && curr_pos == pos\n    {\n        return Ok(());\n    }\n    Err(std::io::Error::new(\n        ErrorKind::InvalidData,","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/common/io/src/cursor_ext/cursor_read_string_ext.rs#L163-L199","documentation":"Raised by `CursorReadStringExt::fast_read_quoted_text` when it scans a single-quoted literal but never encounters the terminating `'`. It reports the whole buffer consumed so far so the developer can locate where the quote should have appeared.","triggerScenarios":"Calling `fast_read_quoted_text` on input like `'hello world` — quote opens the literal but EOF is reached before a matching `'` is consumed by the fast-path scanner.","commonSituations":"Hand-written query/text literals missing the closing quote, template strings where a variable value contained content that consumed the closing quote, or line-oriented input that split a literal across records.","solutions":["Examine the consumed buffer in the error and add the missing closing `'` at the end.","Ensure quote characters inside the literal are escaped (`\\'`) so they do not prematurely interact with the scanner.","Fix the generator/serializer emitting the literal to always close quotes.","Add a pre-parse sanity check that the literal contains an even number of unescaped quotes."],"exampleFix":"// before\nlet input = \"'hello world\";\n// after\nlet input = \"'hello world'\";","handlingStrategy":"validation","validationCode":"fn balanced_quotes(input: &str, quote: char) -> bool {\n    let mut escaped = false;\n    let mut count = 0;\n    for c in input.chars() {\n        if escaped { escaped = false; continue; }\n        match c { '\\\\' => escaped = true, _ if c == quote => count += 1, _ => {} }\n    }\n    count % 2 == 0\n}","typeGuard":"fn is_closed_single_quoted(s: &str) -> bool {\n    s.starts_with('\\'') && s.len() >= 2 && s.ends_with('\\'')\n}","tryCatchPattern":"match fast_read_quoted_text(&mut buf) {\n    Ok(s) => s,\n    Err(e) => {\n        let consumed = e.to_string(); // includes consumed buf\n        return Err(anyhow!(\"missing closing quote; consumed: {consumed}\"));\n    }\n}","preventionTips":["Count unescaped single quotes before parsing; require an even number.","Escape embedded quotes as \\'.","Ensure multi-line inputs aren't split mid-literal by line-oriented readers."],"tags":["parsing","string-literal","unterminated"],"backgroundTag":"unterminated-string-literal","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}