Add specific error type (NotSupportedError) when parsing not supported sentence#85
Merged
icholy merged 1 commit intoadrianmo:masterfrom Dec 9, 2021
Merged
Conversation
icholy
reviewed
Dec 9, 2021
…d sentence
Example:
```go
var notSupportedErr *nmea.NotSupportedError
if errors.As(err, ¬SupportedErr) {
fmt.Printf("Prefix %s is not supported\n", notSupportedErr.Prefix)
}
```
626a1fc to
fdf5d11
Compare
icholy
approved these changes
Dec 9, 2021
Collaborator
|
Also btw, you don't need to make that err a pointer in your example: s, err := nmea.Parse(sentence)
if err != nil {
var nserr nmea.NotSupportedError
if errors.As(err, &nserr) {
log.Println(err)
continue
}
return err
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add specific error type (NotSupportedError) when parsing not supported sentence so it would be easier to distinguish these kinds of cases from other parse errors (crc etc).
Example :
For example I am testing stuff atm with Ublox GPS and it sends
$GNTXT,01,01,02,FWVER=TIM 1.10*50messages which trigger errors. I would like to have easy way to skip these lines (maybe log differently) but I am still interested in other parse problems - ala CRC errors.I also modified one of the examples in README to show type switch syntax which is handy when you need specific code block of different sentence types.