You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remove duplicated section from error_management.md (#1529)
* Remove duplicated section from error_management.md
The section explaining the three different error types was duplicated (with minimal changes between the two sections). This (small) PR removes the redundancy.
* Update doc/error_management.md
Co-authored-by: Geoffroy Couprie <[email protected]>
Copy file name to clipboardExpand all lines: doc/error_management.md
+3-8
Original file line number
Diff line number
Diff line change
@@ -22,10 +22,10 @@ pub enum Err<E> {
22
22
The result is either an `Ok((I, O))` containing the remaining input and the
23
23
parsed value, or an `Err(nom::Err<E>)` with `E` the error type.
24
24
`nom::Err<E>` is an enum because combinators can have different behaviours
25
-
depending on the value:
25
+
depending on the value. The `Err<E>` enum expresses 3 conditions for a parser error:
26
+
-`Incomplete` indicates that a parser did not have enough data to decide. This can be returned by parsers found in `streaming` submodules to indicate that we should buffer more data from a file or socket. Parsers in the `complete` submodules assume that they have the entire input data, so if it was not sufficient, they will instead return a `Err::Error`. When a parser returns `Incomplete`, we should accumulate more data in the buffer (example: reading from a socket) and call the parser again
26
27
-`Error` is a normal parser error. If a child parser of the `alt` combinator returns `Error`, it will try another child parser
27
-
-`Failure` is an error from which we cannot recover: The `alt` combinator will not try other branches if a child parser returns `Failure`. This is used when we know we were in the right branch of `alt` and do not need to try other branches
28
-
-`Incomplete` indicates that a parser did not have enough data to decide. This can be returned by parsers found in `streaming` submodules. Parsers in the `complete` submodules assume that they have the entire input data, so if it was not sufficient, they will instead return a `Err::Error`. When a parser returns `Incomplete`, we should accumulate more data in the buffer (example: reading from a socket) and call the parser again
28
+
-`Failure` is an error from which we cannot recover: The `alt` combinator will not try other branches if a child parser returns `Failure`. If we know we were in the right branch (example: we found a correct prefix character but input after that was wrong), we can transform a `Err::Error` into a `Err::Failure` with the `cut()` combinator
29
29
30
30
If we are running a parser and know it will not return `Err::Incomplete`, we can
31
31
directly extract the error type from `Err::Error` or `Err::Failure` with the
@@ -68,11 +68,6 @@ directly at the call site.
68
68
See [the JSON parser](https://github.com/Geal/nom/blob/5405e1173f1052f7e006dcb0b9cfda2b06557b65/examples/json.rs#L209-L286)
69
69
for an example of choosing different error types at the call site.
70
70
71
-
The `Err<E>` enum expresses 3 conditions for a parser error:
72
-
-`Incomplete` indicates that a parser did not have enough data to decide. This can be returned by parsers found in `streaming` submodules to indicate that we should buffer more data from a file or socket. Parsers in the `complete` submodules assume that they have the entire input data, so if it was not sufficient, they will instead return a `Err::Error`
73
-
-`Error` is a normal parser error. If a child parser of the `alt` combinator returns `Error`, it will try another child parser
74
-
-`Failure` is an error from which we cannot recover: The `alt` combinator will not try other branches if a child parser returns `Failure`. If we know we were in the right branch (example: we found a correct prefix character but input after that was wrong), we can transform a `Err::Error` into a `Err::Failure` with the `cut()` combinator
0 commit comments