Skip to content

fix: include line numbers in HTML parser error messages (GH #233) - #291

Draft
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/fix-html-error-line-numbers
Draft

toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/fix-html-error-line-numbers

Conversation

@toddr-bot

@toddr-bot toddr-bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

What

HTML parser errors now include line numbers in their stringified output.

Why

Error::as_string() only showed line numbers for errors from the XML parser domain (XML_ERR_FROM_PARSER). HTML parser errors use XML_ERR_FROM_HTML (domain 5), so their line numbers were silently dropped — even though libxml2 populates them in the xmlError struct. This made debugging HTML parsing errors unnecessarily difficult (GH #233).

How

Added a fallback elsif branch in as_string() that displays line N: for any error with a line number but no file, regardless of domain. The existing Entity: line N format for XML parser domain errors is preserved unchanged.

Before:

HTML parser error : Unexpected end tag : i

After:

line 5: HTML parser error : Unexpected end tag : i

Testing

  • New test t/46err_html_line.t verifies HTML errors include line numbers and XML error format is unchanged
  • Full test suite passes (80 test files)

Quality Report

Changes: 2 files changed, 91 insertions(+)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan

Error::as_string() only showed line numbers for errors from the XML
parser domain (XML_ERR_FROM_PARSER). HTML parser errors use a different
domain (XML_ERR_FROM_HTML), so their line numbers were silently dropped
even though libxml2 populates them in the xmlError struct.

Add a fallback branch that displays "line N:" for any error that has a
line number but no file, regardless of domain. The existing "Entity:
line N" format for XML parser errors is preserved unchanged.
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.

1 participant