Skip to content

Commit

Permalink
feat: New error to highlight unrecognized responses
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo committed Sep 3, 2024
1 parent b83ce30 commit 990321d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ func (e ErrNotSupported[T]) Is(target error) bool {
return ok
}

type ErrUnrecognizedResponse[T StringLike] struct {
Actual T
Expected T
}

func (e ErrUnrecognizedResponse[T]) Error() string {
return fmt.Sprintf("unrecognized response. expected: %s (or na). got: %s", e.Expected, e.Actual)

Check warning on line 35 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L34-L35

Added lines #L34 - L35 were not covered by tests
}

// ErrNoProtocols is the error returned when the no protocols have been
// specified.
var ErrNoProtocols = errors.New("no protocols specified")
Expand Down Expand Up @@ -146,6 +155,9 @@ func readProto[T StringLike](proto T, r io.Reader) error {
case "na":
return ErrNotSupported[T]{[]T{proto}}
default:
return fmt.Errorf("unrecognized response: %s", tok)
return ErrUnrecognizedResponse[T]{
Actual: tok,
Expected: proto,

Check warning on line 160 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L158-L160

Added lines #L158 - L160 were not covered by tests
}
}
}

0 comments on commit 990321d

Please sign in to comment.