Skip to content

Commit

Permalink
Improve gumbo error messages during tree construction
Browse files Browse the repository at this point in the history
adding punctuation, cleaning up whitespace, and naming the input tag

If the message was:

> 1:13: ERROR: This tag isn't allowed here  Currently open tags: html, body, div, table.

it is now something like:

> 1:13: ERROR: Start tag 'svg' isn't allowed here. Currently open tags: html, body, div, table.
  • Loading branch information
flavorjones committed Apr 27, 2023
1 parent cf3bc38 commit 37c29a5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions gumbo-parser/src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static void print_tag_stack (
const GumboParserError* error,
GumboStringBuffer* output
) {
print_message(output, " Currently open tags: ");
print_message(output, " Currently open tags: ");
for (unsigned int i = 0; i < error->tag_stack.length; ++i) {
if (i) {
print_message(output, ", ");
Expand Down Expand Up @@ -347,15 +347,19 @@ static void handle_parser_error (
if (error->parser_state == GUMBO_INSERTION_MODE_INITIAL) {
print_message(output, "You must provide a doctype");
} else {
print_message(output, "Premature end of file");
print_message(output, "Premature end of file.");
print_tag_stack(error, output);
}
return;
case GUMBO_TOKEN_START_TAG:
print_message(output, "Start tag '%s' isn't allowed here.",
gumbo_normalized_tagname(error->input_tag));
print_tag_stack(error, output);
return;
case GUMBO_TOKEN_END_TAG:
print_message(output, "That tag isn't allowed here");
print_message(output, "Eng tag '%s' isn't allowed here.",
gumbo_normalized_tagname(error->input_tag));
print_tag_stack(error, output);
// TODO(jdtang): Give more specific messaging.
return;
}
}
Expand Down

0 comments on commit 37c29a5

Please sign in to comment.