hasura/graphql-engine · error · Error

invalid number literal found: {0:?}

Error message

invalid number literal found: {0:?}

What it means

Wrapper error: the lexer's number sub-scanner (number::Error) failed while scanning a numeric literal, e.g. "1e" without exponent digits, "..2", or a stray '.'.

Source

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

    ///
    /// Unexpected characters are characters that _do_ exist in the GraphQL
    /// language, but is not expected at the current position in the document.
    #[error("unexpected character in the document: {0:?}")]
    UnexpectedCharacter(char),

    /// The input source was unexpectedly terminated
    ///
    /// Emitted when the current token requires a succeeding character, but
    /// the source has reached EOF. Emitted when scanning e.g. `"1."`.
    #[error("end of file reached when expecting further input")]
    UnexpectedEndOfFile,

    /// An invalid string literal was found
    #[error("invalid string literal found: {0:?}")]
    InvalidString(string::Error),

    /// An invalid number literal was found
    #[error("invalid number literal found: {0:?}")]
    InvalidNumber(number::Error),

    // An invalid graphql name
    #[error("invalid graphql name: {0}")]
    InvalidGraphQlName(String),
}

impl From<ast::common::InvalidGraphQlName> for Error {
    fn from(error: ast::common::InvalidGraphQlName) -> Self {
        Error::InvalidGraphQlName(error.0)
    }
}

pub type Result = core::result::Result<Spanning<Token>, Positioned<Error>>;

#[inline]
fn consume_ascii_chars<F>(data: &[u8], mut f: F) -> usize
where

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Inspect the inner number::Error detail at the reported position
  2. Correct the literal (exponent digits, single decimal point)
  3. Render numbers with a GraphQL-safe formatter rather than locale formatting

Example fix

# before
{ stats(value: 1e) { id } }
# after
{ stats(value: 1e0) { id } }
Defensive patterns

Strategy: validation

Validate before calling

// validate numeric literals in generated queries
fn graphql_number_ok(n: &str) -> bool {
    n.parse::<f64>().is_ok() && !n.contains(",") && !n.contains('..') && !n.ends_with(['.', 'e', 'E'])
}

Try / catch

On InvalidNumber(inner), surface the inner number::Error and byte position to the query author.

Prevention

When it happens

Trigger: Lexing documents containing malformed numbers: missing exponent digits, double dots, invalid characters after a sign, per the number::Error variants.

Common situations: Formatting numbers with locale-specific separators, broken string interpolation of floats, or hand-typed queries with typos.

Related errors


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