{"record":{"id":"19e2b6e4f09d06e5","repo":"hasura/graphql-engine","slug":"unexpected-character-in-string-0","errorCode":null,"errorMessage":"unexpected character in string: {0:?}","messagePattern":"unexpected character in string: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/crates/graphql/lang-graphql/src/lexer/string.rs","lineNumber":22,"sourceCode":"\n#[derive(Error, Debug, PartialEq, Eq, Clone)]\npub enum Error {\n    #[error(\"expected a \\\" but found: {0:?}\")]\n    StartingSequenceNotFound(Option<u8>),\n\n    /// An unterminated string literal was found\n    ///\n    /// Apart from forgetting the ending `\"`, terminating a string within a\n    /// Unicode escape sequence or having a line break in the string also\n    /// causes this error.\n    #[error(\"string is unterminated\")]\n    Unterminated,\n\n    /// An unknown character in a string literal was found\n    ///\n    /// This occurs when an invalid source character is found in a string\n    /// literal, such as ASCII control characters.\n    #[error(\"unexpected character in string: {0:?}\")]\n    UnknownCharacterInString(char),\n\n    /// An unknown escape sequence in a string literal was found\n    ///\n    /// Only a limited set of escape sequences are supported, this is emitted\n    /// when e.g. `\"\\l\"` is parsed.\n    #[error(\"unknown escape sequence in string: {0:?}\")]\n    UnknownEscapeSequence(String),\n\n    /// An invalid unicode escape sequence in a string literal was found, and\n    /// an error message is provided.\n    ///\n    /// This began with `\"\\u\"` being parsed and then something going wrong.\n    #[error(\"invalid unicode escape sequence in string. {0:?}\")]\n    InvalidUnicodeEscapeSequence(String),\n}\n\npub struct Consumed {","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/graphql/lang-graphql/src/lexer/string.rs#L4-L40","documentation":"Thrown by the GraphQL lexer's string scanner when it encounters a character that is not allowed inside a GraphQL string literal. GraphQL strings may only contain printable characters plus supported escapes; raw ASCII control characters (e.g. a literal newline or tab inside a normal string) trigger this. The offending character is included in the message.","triggerScenarios":"Scanning a query or SDL document containing a normal (non-block) string with an embedded raw control character, e.g. \"a\\nb\" written with a real newline instead of \\n, or a pasted string with a hidden control char.","commonSituations":"Multiline query text embedded in source code without triple-quote block strings, copy-pasted queries with invisible characters, or queries built via string concatenation across lines.","solutions":["Replace the raw newline/tab with the escape sequence \\n or \\t","Use a block string (\"\"\"...\"\"\") for multiline text","Sanitize/inspect input for control characters before parsing"],"exampleFix":"// before\nlet q = \"{ set(name: \\\"line1\nline2\\\") }\"; // raw newline inside string\n// after\nlet q = \"{ set(name: \\\"line1\\\\nline2\\\") }\"; // escaped newline","handlingStrategy":"validation","validationCode":"fn has_raw_control_chars(s: &str) -> bool {\n    s.chars().any(|c| (c.is_control() && c != '\\t') || c == '\\n' || c == '\\r')\n}\nassert!(!has_raw_control_chars(query));","typeGuard":null,"tryCatchPattern":"match graphql_lexer::Lexer::new(src).next() { Some(Err(e)) => /* report e with position */ , _ => {} }","preventionTips":["Escape newlines/tabs as \\\\n/\\\\t in normal strings","Use block strings for multiline text","Lint embedded query strings for control characters"],"tags":["graphql","lexer","string-literal","parsing"],"backgroundTag":"graphql-syntax-error","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}