Skip to content

Commit 552a3c9

Browse files
committed
fix: properly rewrite errors for watch api, part 2
1 parent cdef621 commit 552a3c9

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

internal/services/shared/errors.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ func rewriteError(ctx context.Context, err error, config *ConfigForErrors) error
177177
return status.Errorf(codes.Canceled, "watch canceled by user: %s", err)
178178
case errors.As(err, &datastore.WatchDisconnectedError{}):
179179
return status.Errorf(codes.ResourceExhausted, "watch disconnected: %s", err)
180+
case errors.As(err, &datastore.WatchRetryableError{}):
181+
// Unavailable indicates its transient and safe to retry.
182+
return status.Error(codes.Unavailable, err.Error())
180183
case errors.As(err, &datastore.CounterAlreadyRegisteredError{}):
181184
return spiceerrors.WithCodeAndReason(err, codes.FailedPrecondition, v1.ErrorReason_ERROR_REASON_COUNTER_ALREADY_REGISTERED)
182185
case errors.As(err, &datastore.CounterNotRegisteredError{}):

internal/services/shared/errors_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package shared
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"testing"
78

@@ -116,6 +117,13 @@ func TestRewriteError(t *testing.T) {
116117
expectedCode: codes.FailedPrecondition,
117118
expectedContains: "watch is currently disabled: it was disabled",
118119
},
120+
{
121+
name: "watch retryable",
122+
inputError: datastore.NewWatchTemporaryErr(errors.New("server is shutting down")),
123+
config: nil,
124+
expectedCode: codes.Unavailable,
125+
expectedContains: "watch has failed with a temporary condition: server is shutting down. Please retry",
126+
},
119127
{
120128
name: "counter already registered",
121129
inputError: datastore.NewCounterAlreadyRegisteredErr("somecounter", &corev1.RelationshipFilter{ResourceType: "doc"}),

pkg/datastore/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func NewWatchDisabledErr(reason string) error {
136136
// a temporary condition and clients may consider retrying by calling watch again (vs a fatal error).
137137
func NewWatchTemporaryErr(wrapped error) error {
138138
return WatchRetryableError{
139-
error: fmt.Errorf("watch has failed with a temporary condition: %w. please retry the watch", wrapped),
139+
error: fmt.Errorf("watch has failed with a temporary condition: %w. Please retry", wrapped),
140140
}
141141
}
142142

0 commit comments

Comments
 (0)