feat: surface error catalogue extensions on GraphQLError

Closed
TI
1mo ago
+166-1

Motivation

Infrahub 1.10 introduced the error catalogue: every GraphQL error carries extensions.code (string), extensions.http_status (int) and extensions.data (typed payload). As discussed in opsmill/infrahub#9815, consumers currently have to re-parse GraphQLError message text because the SDK does not read these extensions, and the exception message embeds the full rendered query and raw error payload — which leaks large (and potentially sensitive) payloads into logs and tracebacks.

Changes

  • GraphQLError.details — each entry of the response's errors array parsed into a structured, frozen GraphQLErrorDetail (message, catalogue code, http_status, data, path).
  • GraphQLError.codes — the catalogue codes present in the response.
  • The exception message now joins the server-provided error messages only. The executed query and variables remain available on the query/variables attributes but no longer appear in str(exc). The existing An error occurred while executing the GraphQL Query prefix is preserved so substring matches keep working.
  • Parsing is defensive: non-dict entries and malformed extensions degrade to message-only details instead of raising (some in-repo call sites construct GraphQLError with non-standard payloads).

Scope

This is the minimal parsing layer. Full typed binding generation from schema/error-catalogue.json (per the infp-468 spec, tracked separately for this repo) can build on GraphQLErrorDetail later.

Testing

  • New unit tests cover extensions parsing, code extraction, message conciseness (query/variables never in str(exc)), and malformed-input tolerance.
  • invoke format lint-code clean (ruff, ty, mypy).
  • Full unit suite: no new failures (the 4 failing ctl tests on a clean stable checkout fail identically without this change).

Summary by cubic

Exposes Infrahub GraphQL error catalogue metadata on GraphQLError and stops embedding the query and variables in exception messages. Parsing now tolerates scalar (non-list) errors, and locations remains only on the raw errors payload.

  • New Features

    • GraphQLError.details: list of GraphQLErrorDetail with message, code, http_status, data, path (parses defensively; accepts list or scalar errors; locations intentionally not exposed).
    • GraphQLError.codes: the catalogue codes present in the response.
    • Exception message now joins server error messages only; query and variables stay on attributes, not in str(error).
  • Migration

    • If you parsed str(GraphQLError) for queries or payloads, use error.query, error.variables, or error.details instead.