Skip to content

Add specific error type (NotSupportedError) when parsing not supported sentence#85

Merged
icholy merged 1 commit intoadrianmo:masterfrom
aldas:error_for_parse_not_supported
Dec 9, 2021
Merged

Add specific error type (NotSupportedError) when parsing not supported sentence#85
icholy merged 1 commit intoadrianmo:masterfrom
aldas:error_for_parse_not_supported

Conversation

@aldas
Copy link
Copy Markdown
Collaborator

@aldas aldas commented Dec 9, 2021

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 :

s, err := nmea.Parse(sentence)
if err != nil {
	var notSupportedErr *nmea.NotSupportedError
	if errors.As(err, &notSupportedErr) {
		log.Printf("Prefix %s is not supported\n", notSupportedErr.Prefix)
		continue // read next line
	}
	return err
}

For example I am testing stuff atm with Ublox GPS and it sends $GNTXT,01,01,02,FWVER=TIM 1.10*50 messages 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.

Comment thread sentence.go Outdated
@aldas aldas requested a review from icholy December 9, 2021 19:32
@aldas aldas changed the title Add specific error type (ParseNotSupportedError) when parsing not supported sentence Add specific error type (ErrNotSupported) when parsing not supported sentence Dec 9, 2021
…d sentence

Example:
```go
var notSupportedErr *nmea.NotSupportedError
if errors.As(err, &notSupportedErr) {
	fmt.Printf("Prefix %s is not supported\n", notSupportedErr.Prefix)
}
```
@aldas aldas force-pushed the error_for_parse_not_supported branch from 626a1fc to fdf5d11 Compare December 9, 2021 20:02
@icholy icholy merged commit 2e640c1 into adrianmo:master Dec 9, 2021
@icholy
Copy link
Copy Markdown
Collaborator

icholy commented Dec 9, 2021

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
}

@adrianmo adrianmo changed the title Add specific error type (ErrNotSupported) when parsing not supported sentence Add specific error type (NotSupportedError) when parsing not supported sentence Dec 10, 2021
@aldas aldas deleted the error_for_parse_not_supported branch December 16, 2021 13:52
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.

2 participants