Skip to content

Unclosed child elements produce confusing error messages on parent elements #571

Description

@bensheldon

This observation came out of trying to make sense of herb analyze warnings: an unmatched unclosed tag also showed up as an opened-without-close tag on the parent. And because the parent error appeared first, especially on some really big HTML with a deeply nested unclosed tag, I was very confused because I was like but it's right there.

Here's an example in the playground:

https://herb-tools.dev/playground#DwFwhgRgNgpgfAKAAROAehAE0e814ILAAWAjHAMoD2AtjCMQJYB2A5ugM4AOYzc6ZOEA

<table>
 <!-- lots and lots of content -->
 </td>
 <!-- lots and lots of content -->
</table>

<h1>Something</span></h1>

...with output like:

@ DocumentNode (location: (1:0)-(7:25))
├── errors: (1 item)
│   └── @ UnclosedElementError (location: (5:0)-(5:2))
│       ├── message: "Tag `<table>` opened at (1:1) was never closed before the end of document."
│       └── opening_tag: "table" (location: (1:1)-(1:6))
|
│   IMAGINE TONS OF OTHER OUTPUT RIGHT HERE       
│  
└── children: (8 items)
    ├── @ HTMLElementNode (location: (1:0)-(3:7))
    │   ├── errors: (1 item)
    │   │   └── @ TagNamesMismatchError (location: (3:4)-(3:6))
    │   │       ├── message: "Opening tag `<table>` at (1:1) closed with `</td>` at (3:4)."
    │   │       ├── opening_tag: "table" (location: (1:1)-(1:6))
    │   │       └── closing_tag: "td" (location: (3:4)-(3:6))
    │   │       

What would make it looks less confusing?

  • Changing herb analyze output to just show the errors so maybe they'd be a little closer visually and I could reason it out easier
  • There's sorta something wrong with the output if the child says "Opening tag <table> at (1:1) closed with </td> at (3:4)." but the parent says "Tag <table> opened at (1:1) was never closed before the end of document." The child's error says it closed the parent, but the parent's error says it was never closed. I dunno if they can have awareness of eachother, but they seem causative.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingparser

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions