Skip to content

ef: Improve parse error messages with context, caret, and field hints#14

Open
jeso-mchp wants to merge 1 commit intomasterfrom
master.error-messages
Open

ef: Improve parse error messages with context, caret, and field hints#14
jeso-mchp wants to merge 1 commit intomasterfrom
master.error-messages

Conversation

@jeso-mchp
Copy link
Copy Markdown
Contributor

The FRAME-SPEC parse errors are not so easy to read. This changes the parse errors to a more human friendly format:

  #Before:
  $ ef hex eth bogus
  Parse error! arg# 2 out of 3, cmd_idx = 1

  $ ef hex bogus
  Parse error! arg# 0 out of 2, cmd_idx = 0

  $ ef bogus
  Parse error! arg# 0 out of 1, cmd_idx = 0

  $ ef hex eth ipv4 badfield
  Parse error! arg# 3 out of 4, cmd_idx = 1

  # After:
  $ ef hex eth bogus
  error: 'bogus' is not a field of 'eth' or a recognized header
    hex eth bogus
            ^^^^^
    valid fields for 'eth': dmac smac et

  $ ef hex bogus
  error: 'bogus' is not a recognized header or command
    hex bogus
        ^^^^^

  $ ef bogus
  error: unexpected token 'bogus'
    bogus
    ^^^^^

  $ ef hex eth ipv4 badfield
  error: 'badfield' is not a field of 'ipv4' or a recognized header
    hex eth ipv4 badfield
                 ^^^^^^^^
    valid fields for 'ipv4': ver ihl dscp ecn len id flags offset ttl proto chksum sip dip

Replace the unhelpful "Parse error! arg# N out of M" with structured diagnostics on stderr: error headline identifying the bad token and which header it was expected in, the full command with a caret pointing to the exact token, and a list of valid fields when applicable.

A global parse_err_ctx_t side-channel records context during parsing so the top-level error reporter can produce accurate messages without changing any parser function signatures.

Replace the unhelpful "Parse error! arg# N out of M" with structured
diagnostics on stderr: error headline identifying the bad token and
which header it was expected in, the full command with a caret pointing
to the exact token, and a list of valid fields when applicable.

A global parse_err_ctx_t side-channel records context during parsing so
the top-level error reporter can produce accurate messages without
changing any parser function signatures.
@jeso-mchp jeso-mchp requested review from igudich April 9, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant