hasura/graphql-engine · error · Error

unknown escape sequence in string: {0:?}

Error message

unknown escape sequence in string: {0:?}

What it means

Thrown when a backslash escape inside a GraphQL string literal is not one of the recognized escape sequences (\" \\ \/ \b \f \n \r \t \uXXXX). The invalid sequence text is included in the message.

Source

Thrown at v3/crates/graphql/lang-graphql/src/lexer/string.rs:29

    ///
    /// Apart from forgetting the ending `"`, terminating a string within a
    /// Unicode escape sequence or having a line break in the string also
    /// causes this error.
    #[error("string is unterminated")]
    Unterminated,

    /// An unknown character in a string literal was found
    ///
    /// This occurs when an invalid source character is found in a string
    /// literal, such as ASCII control characters.
    #[error("unexpected character in string: {0:?}")]
    UnknownCharacterInString(char),

    /// An unknown escape sequence in a string literal was found
    ///
    /// Only a limited set of escape sequences are supported, this is emitted
    /// when e.g. `"\l"` is parsed.
    #[error("unknown escape sequence in string: {0:?}")]
    UnknownEscapeSequence(String),

    /// An invalid unicode escape sequence in a string literal was found, and
    /// an error message is provided.
    ///
    /// This began with `"\u"` being parsed and then something going wrong.
    #[error("invalid unicode escape sequence in string. {0:?}")]
    InvalidUnicodeEscapeSequence(String),
}

pub struct Consumed {
    /// Number of line breaks consumed.
    pub line_breaks: usize,
    /// Number of characters consumed without hitting a further line break.
    pub chars_without_further_line_break: usize,
}

impl Consumed {

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Double the backslash for a literal backslash: "\\\\"
  2. Use the supported escape (e.g. \u006c instead of \l)
  3. Move regex/paths out of the query or encode them differently

Example fix

# before
{ match(pattern: "\\d+") }   # \d is not a GraphQL escape
# after
{ match(pattern: "\\\\d+") }  # escaped backslash + d
Defensive patterns

Strategy: validation

Validate before calling

const VALID: [&str; 8] = ["\\\"","\\\\","\\/","\\b","\\f","\\n","\\r","\\t"];
// verify every escape in the string is in VALID or starts with \\u

Try / catch

Catch the lexer Error and inspect the InvalidString(string::Error::UnknownEscapeSequence(..)) variant to surface which escape failed.

Prevention

When it happens

Trigger: Parsing a document with an escape like "\\l", "\\x41", or a shell/regex-style escape such as "\\d+" inside a GraphQL string.

Common situations: Embedding regular expressions, Windows paths, or LaTeX-like text in GraphQL string arguments without doubling the backslashes; translating queries from another language that supports more escapes.

Related errors


AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28). Data as JSON: /api/errors/10c377a28334c61b. Report an issue: GitHub.