Skip to content

Commit c7c3b07

Browse files
committed
refactor: rename+improve client.ErrEventNotSupported
`client.ErrEventNotSupported` was a simple sentinel with no information. Replaced it with `client.EventNotSupportedError`, a struct implementing error with the offending TypeURL included. Signed-off-by: Laura Brehm <[email protected]>
1 parent 425fa0f commit c7c3b07

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

cmd/talosctl/cmd/talos/events.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ var eventsCmd = &cobra.Command{
6666

6767
event, err := client.UnmarshalEvent(ev)
6868
if err != nil {
69-
if errors.Is(err, client.ErrEventNotSupported) {
69+
var errBadEvent client.EventNotSupportedError
70+
if errors.As(err, &errBadEvent) {
7071
return nil
7172
}
7273

pkg/machinery/client/events.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,15 @@ import (
2020
"github.com/siderolabs/talos/pkg/machinery/proto"
2121
)
2222

23-
// ErrEventNotSupported is returned from the event decoder when we encounter an unknown event.
24-
var ErrEventNotSupported = errors.New("event is not supported")
23+
// EventNotSupportedError is returned from the event decoder when we encounter an unknown event.
24+
type EventNotSupportedError struct {
25+
TypeURL string
26+
}
27+
28+
// Error implements the error interface.
29+
func (e EventNotSupportedError) Error() string {
30+
return fmt.Sprintf("event is not supported: %s", e.TypeURL)
31+
}
2532

2633
// EventsOptionFunc defines the options for the Events API.
2734
type EventsOptionFunc func(opts *machineapi.EventsRequest)
@@ -249,9 +256,10 @@ func UnmarshalEvent(event *machineapi.Event) (*Event, error) {
249256
}
250257

251258
if msg == nil {
252-
log.Printf("event not supported: %s", typeURL)
253259
// We haven't implemented the handling of this event yet.
254-
return nil, ErrEventNotSupported
260+
return nil, EventNotSupportedError{
261+
TypeURL: typeURL,
262+
}
255263
}
256264

257265
if err := proto.Unmarshal(event.GetData().GetValue(), msg); err != nil {

0 commit comments

Comments
 (0)