Skip to content

Commit b1b2ce0

Browse files
authored
Merge pull request #2238 from ecordell/fix-crdberror
crdb pool: handle cases with nil errors
2 parents f678be6 + 8f8e832 commit b1b2ce0

File tree

3 files changed

+700
-3
lines changed

3 files changed

+700
-3
lines changed

internal/datastore/crdb/pool/sqlerrors.go

+26-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ type MaxRetryError struct {
3232

3333
func (e *MaxRetryError) Error() string {
3434
if e.MaxRetries == 0 {
35-
return "retries disabled: " + e.LastErr.Error()
35+
if e.LastErr != nil {
36+
return "retries disabled: " + e.LastErr.Error()
37+
}
38+
return "retries disabled"
39+
}
40+
if e.LastErr == nil {
41+
return fmt.Sprintf("max retries reached (%d)", e.MaxRetries)
3642
}
3743
return fmt.Sprintf("max retries reached (%d): %s", e.MaxRetries, e.LastErr.Error())
3844
}
@@ -53,10 +59,19 @@ type ResettableError struct {
5359
Err error
5460
}
5561

56-
func (e *ResettableError) Error() string { return "resettable error" + ": " + e.Err.Error() }
62+
func (e *ResettableError) Error() string {
63+
if e.Err == nil {
64+
return "resettable error"
65+
}
66+
return "resettable error" + ": " + e.Err.Error()
67+
}
68+
5769
func (e *ResettableError) Unwrap() error { return e.Err }
5870

5971
func (e *ResettableError) GRPCStatus() *status.Status {
72+
if e.Err == nil {
73+
return status.New(codes.Unavailable, "resettable error")
74+
}
6075
return spiceerrors.WithCodeAndDetails(
6176
e.Unwrap(),
6277
codes.Unavailable, // return unavailable so clients are know it's ok to retry
@@ -68,10 +83,18 @@ type RetryableError struct {
6883
Err error
6984
}
7085

71-
func (e *RetryableError) Error() string { return "retryable error" + ": " + e.Err.Error() }
86+
func (e *RetryableError) Error() string {
87+
if e.Err == nil {
88+
return "retryable error"
89+
}
90+
return "retryable error" + ": " + e.Err.Error()
91+
}
7292
func (e *RetryableError) Unwrap() error { return e.Err }
7393

7494
func (e *RetryableError) GRPCStatus() *status.Status {
95+
if e.Err == nil {
96+
return status.New(codes.Unavailable, "resettable error")
97+
}
7598
return spiceerrors.WithCodeAndDetails(
7699
e.Unwrap(),
77100
codes.Unavailable, // return unavailable so clients are know it's ok to retry

0 commit comments

Comments
 (0)