Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(error)!: Provide a simple, getting started error #282

Merged
merged 14 commits into from
Jul 7, 2023

Conversation

epage
Copy link
Collaborator

@epage epage commented Jul 7, 2023

The default errors for winnow were a bad experience, making it so the default parameter for PResult / IResult was just there for quick prototyping.

This changes the error to mirror what is inside of toml_edit. It also leverages the work done in #72 to remove generic parameters so it could be the default error for PResult.

This also adjusts Parser::parse to automatically add relevant context back into the error.

Users can use the built-in Display or they can provide their own conversion function.

Note: VerboseError made parsing take 3x as long. The new ContextError makes parsing take 1.1x as long or so.

Fixes #103

epage added 13 commits July 7, 2023 10:20
With the new design, this is not a general purpose error to recommend
but is more helpful for writing tests of generic parsers to easily
verify the failure location.
This is modeled off of `combine` and what I do for errors in `toml_edit`

The main thing lacking is merging it with the input on `Parser::parse`.

Performance is good:
```
json/basic/canada       time:   [9.9270 ms 9.9518 ms 9.9784 ms]
json/unit/canada        time:   [9.0616 ms 9.0910 ms 9.1183 ms]
json/verbose/canada     time:   [31.558 ms 31.722 ms 31.893 ms]
json/context/canada     time:   [12.650 ms 12.679 ms 12.710 ms]
```
This will provide more capabilities out of the box, leading to a better
user experience.  For people who want little error context but high
performance, they can switch the error type.
`ParseError` is a holdover from when it was being returned by
`Parser::parse` but now it is being returned by `Parser::parse_next` or
`Parser::parse_peek`.

The new name is to convey this is what the parser is returning.  This is
opening room for a `ParseError` which will be a concrete type that wraps
`ParserError` when returned by `Parser::parse`.
`VerboseError` was significantly slower (3x parse time) and awkward to
work with (requiring extra input to render).  Instead, `Context` error
serves most purposes and users can write their own.
src/error.rs Fixed Show fixed Hide fixed
@coveralls
Copy link

coveralls commented Jul 7, 2023

Pull Request Test Coverage Report for Build 5490674182

  • 77 of 206 (37.38%) changed or added relevant lines in 9 files are covered.
  • 9 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-1.1%) to 47.804%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/token/mod.rs 12 13 92.31%
src/parser.rs 0 9 0.0%
src/error.rs 27 146 18.49%
Files with Coverage Reduction New Missed Lines %
src/token/mod.rs 1 85.43%
src/parser.rs 2 55.56%
src/error.rs 6 25.9%
Totals Coverage Status
Change from base Build 5476828790: -1.1%
Covered Lines: 1208
Relevant Lines: 2527

💛 - Coveralls

@epage epage force-pushed the error branch 3 times, most recently from f9f8913 to 4811ca9 Compare July 7, 2023 21:22
@epage epage merged commit 17c1f01 into winnow-rs:main Jul 7, 2023
@epage epage deleted the error branch July 7, 2023 21:43
@coveralls
Copy link

coveralls commented Oct 7, 2024

Pull Request Test Coverage Report for Build 5490674182

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 77 of 206 (37.38%) changed or added relevant lines in 9 files are covered.
  • 9 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-1.1%) to 47.804%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/token/mod.rs 12 13 92.31%
src/parser.rs 0 9 0.0%
src/error.rs 27 146 18.49%
Files with Coverage Reduction New Missed Lines %
src/token/mod.rs 1 85.43%
src/parser.rs 2 55.56%
src/error.rs 6 25.9%
Totals Coverage Status
Change from base Build 5476828790: -1.1%
Covered Lines: 1208
Relevant Lines: 2527

💛 - Coveralls

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.

Simplified getting-started error type
2 participants