Skip to content
This repository has been archived by the owner on Aug 26, 2023. It is now read-only.

Standardize errors #112

Merged
merged 5 commits into from
Oct 3, 2018
Merged

Conversation

stevecheckoway
Copy link
Collaborator

All of the standard tokenizer errors are implemented with their given
error code strings.

Each transition of the tokenizer state machine that emit one or more
errors is tested to emit exactly those errors and no others. Those
transitions that do not emit an error are tested to ensure that they do
not.

The GumboError is opaque to callers and the GumboStringBuffer is not
exposed. The error codes of the defined errors as well as the two
encoding errors and a generic parser error are available via
gumbo_error_code.

In Nokogiri, the error code is exposed via
Nokogiri::XML::SyntaxError#str1.

@stevecheckoway stevecheckoway added this to the 2.0 milestone Sep 19, 2018
All of the standard tokenizer errors are implemented with their given
error code strings.

Each transition of the tokenizer state machine that emit one or more
errors is tested to emit exactly those errors and no others. Those
transitions that do not emit an error are tested to ensure that they do
not.

The `GumboError` is opaque to callers and the `GumboStringBuffer` is not
exposed. The error codes of the defined errors as well as the two
encoding errors and a generic parser error are available via
`gumbo_error_code`.

In Nokogiri, the error code is exposed via
`Nokogiri::XML::SyntaxError#str1`.
Replace

```
if (foo) {
  return x();
} else if (bar) {
  return y();
} else {
  return z();
}
```

with

```
if (foo) {
  return x();
}
if (bar) {
  return y();
}
return z();
```
@stevecheckoway
Copy link
Collaborator Author

I've now gone through the parser pretty carefully and tried to fix everything but it needs tests.

Separately, I was hoping to turn on errors for the html5lib tests but those tests are missing a bunch of errors or have the wrong errors (e.g., html5lib/html5lib-tests#108, html5lib/html5lib-tests#109, html5lib/html5lib-tests#110, html5lib/html5lib-tests#111, and html5lib/html5lib-tests#112). Once those are resolved, there are still about 100 test cases that fail due to errors, either in the tests or in gumbo.

The parser now implements the updated tree-construction stage including
producing the same number of errors specified in the html5lib-tests
tree-construction tests (at least it will after the tests are fixed as
per
https://github.com/html5lib/html5lib-tests/compare/master...stevecheckoway:all-error-fixes?expand=1).
@stevecheckoway stevecheckoway merged commit f957a0a into rubys:master Oct 3, 2018
@stevecheckoway stevecheckoway deleted the standardize-errors branch October 3, 2018 09:04
@stevecheckoway stevecheckoway mentioned this pull request Oct 3, 2018
4 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant