Parser Error Messages - #164
Conversation
1fe26ca to
d8f37ce
Compare
d8f37ce to
217d1c9
Compare
|
The before parser ( >>> html(t'<taga x = 1></tagb ..cruft >')
...
tdom.parser.ParsingError: Mismatched closing tag </tagb> at line 1 offset 15 for <taga x = 1> at line 1 offset 0.
>>>html(t'<taga x = 1></taga ..cruft >')
'<taga x="1"></taga>'
>>> |
davepeck
left a comment
There was a problem hiding this comment.
Thanks for banging through this! Left a couple initial comments but TBH I still don't have my head completely wrapped around it; will have more to say when I better understand how all the parts fit together.
| def has_ambiguous_forward_slash( | ||
| self, | ||
| sinfo: OpenTagSourceInfo | TagSourceInfo | None, | ||
| attrs: tuple[TAttribute, ...], |
There was a problem hiding this comment.
I'm wondering if we can simplify this.
Isn't the rule that if the raw text of the tag ends in />, but sinfo.startend is False, then it's an ambiguous forward slash? (We can safely remove the | None from sinfo:, I think?)
If the rule is that straightforward, then we don't need attrs at all...
There was a problem hiding this comment.
Yeah I saw this too I think maybe a few iterations ago there was no startend and now its in there and I can't tell if they are redundant or not (!!). I need to explore that and maybe clean it up.
The sinfo=None situation handles the situation where we are not tracking extra source information. I wanted to try to keep it optional in case it needed to be turned off for performance or whatever. This function still works and just says "no ambiguous slash here (because I couldn't check)". It isn't great but it keeps the "decision" all in one place.
| pass | ||
|
|
||
|
|
||
| class ParsingAssertionError(ParsingError): |
There was a problem hiding this comment.
I think of TemplatingError as meaning "hey, that template you gave me is busted." That's a kind of exception our users will want to capture.
On the other hand, ParsingAssertionError sorta means "our parser is unexpectedly busted" which feels like it's not a TemplatingError.
I wonder if we should remove this and just use a grab-bag of approaches as appropriate:
assert(for instance,assert starttag_text is not Noneinget_starttag_span(); shouldn't be possible insideTemplateParserunless there's a bug in our code)RuntimeError(for instance, ifself.source is Noneinget_source(), which meansTemplateParserwas invoked from the outside in the wrong order)- ??? if we hit an
OpenTFragmentinvalidate_end_tag(). Maybe a different choice of types would help clarify that this case can never happen?
There was a problem hiding this comment.
Yeah I think we need to play around with it when the processor handling is in too. We as library authors might want the same debugging information that the end-user would get with a caught message, ie. "our parser is unexpectedly busted ... and it got busted INSIDE the 15th nested component call during processing this 100 MB HTML file, etc.". I think some of these might be a bug in the HTMLParser itself or our expectations of it.
The Fragment issue I think is a refactor we need to make that I tried before and maybe after this settles out we'd go back in and try to sort that out. It comes up I think in other places as well.
| self.sinfo_table = {} | ||
| self.tcomponent_children = {} | ||
|
|
||
| def run_unclosed_ambiguous_slash_checks( |
There was a problem hiding this comment.
I'm still wrapping my head around this! Lots of machinery here, although it really is a gnarly case. Fun stuff and/or crazymaking stuff, can't decide which. 馃槄
Yeah, I think it鈥檚 fine for this case too, but it鈥檚 a useful asymmetry to keep our eyes on. We have a reliable |
Added parser error messages.
TemplatingErrorParsingError,ParsingAssertionError,AttributeParsingErrorTemplateParserimprovementstcomponent_childrenattributechildrenTemplateduring processing. Now we keep them around during parsing for error handling to try to figure out why tags are not closed or don't match correctly, etc.make_mismatch_error,make_invalid_endtag_error,run_unclosed_ambiguous_slash_checks,has_ambiguous_forward_slashandget_closed_tcompsSourceReaderchangesspan_to_reprandspan_to_template- these might get refactored later I just tried to matchup the older usage with the newer tools for now.