Skip to content

Commit 990321d

Browse files
committed
feat: New error to highlight unrecognized responses
1 parent b83ce30 commit 990321d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

client.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ func (e ErrNotSupported[T]) Is(target error) bool {
2626
return ok
2727
}
2828

29+
type ErrUnrecognizedResponse[T StringLike] struct {
30+
Actual T
31+
Expected T
32+
}
33+
34+
func (e ErrUnrecognizedResponse[T]) Error() string {
35+
return fmt.Sprintf("unrecognized response. expected: %s (or na). got: %s", e.Expected, e.Actual)
36+
}
37+
2938
// ErrNoProtocols is the error returned when the no protocols have been
3039
// specified.
3140
var ErrNoProtocols = errors.New("no protocols specified")
@@ -146,6 +155,9 @@ func readProto[T StringLike](proto T, r io.Reader) error {
146155
case "na":
147156
return ErrNotSupported[T]{[]T{proto}}
148157
default:
149-
return fmt.Errorf("unrecognized response: %s", tok)
158+
return ErrUnrecognizedResponse[T]{
159+
Actual: tok,
160+
Expected: proto,
161+
}
150162
}
151163
}

0 commit comments

Comments
 (0)