Skip to content

feat(errors): include byte offset and path in Phase 1 parse errors #23

@membphis

Description

@membphis

Problem

qjd_parse currently returns an opaque QJD_PARSE_ERROR on malformed JSON with no position information. Callers cannot tell the user where the JSON is broken, making debugging difficult.

Proposal

Extend the error surface to include:

  1. Byte offset of the first invalid byte detected during Phase 1 (structural scan).
  2. Optionally a path context string (e.g. "[42]" for an error inside the 43rd array element) — this is harder and may be deferred further.

Minimal viable version: expose the byte offset only.

API sketch

// New field on the existing error type, or a companion query function:
size_t qjd_parse_error_offset(const qjd_doc *doc);

The offset is only meaningful when qjd_parse returns QJD_PARSE_ERROR; it is SIZE_MAX otherwise.

Implementation notes

  • validate_brackets in src/scan/mod.rs already returns the failing usize offset; it is currently discarded.
  • Store the error offset in Document and expose it via the new FFI call.
  • Update the LuaJIT wrapper to surface the offset in the error message string: "JSON parse error at byte 1234".
  • Lua busted tests: verify offset is correct for truncated input, unbalanced braces, and bare invalid bytes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions