Skip to content

glz::generic: name key and types in access errors - #3007

Merged
stephenberry merged 2 commits into
mainfrom
generic-access-errors
Oct 16, 2026
Merged

stephenberry merged 2 commits into
mainfrom
generic-access-errors

Conversation

@stephenberry

Copy link
Copy Markdown
Owner

Closes #3001

glz::generic access errors now say what went wrong:

  • Missing key on a const generic: glz::generic key not found: "missing" (still std::runtime_error).
  • get<T>() type mismatch: glz::generic get: expected double, but holds string.
  • Key or index on the wrong type: glz::generic key "key": expected object, but holds array / glz::generic index: expected array, but holds string.

Type mismatches throw the new glz::bad_generic_access, which derives from std::bad_variant_access, so existing handlers still catch it. Builds without exceptions still abort. The get_*() and as<T>() accessors get the new messages through get<T>().

Tests are in exceptions_test, and docs/generic-json.md is updated.

@packit-as-a-service

Copy link
Copy Markdown

@packit-as-a-service

Copy link
Copy Markdown

@stephenberry
stephenberry merged commit fffc946 into main Oct 16, 2026
65 of 66 checks passed
@stephenberry
stephenberry deleted the generic-access-errors branch October 16, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

glz::generic key access has uninformative error messsages

1 participant