forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce custom errors and mark RPC related errors as temporar…
…y so that they can be retried in pipeline
- Loading branch information
1 parent
f8eadfe
commit 8f1f6b7
Showing
9 changed files
with
118 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package serrors | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
const ( | ||
temporary Type = iota | ||
eof | ||
) | ||
|
||
var ( | ||
TemporaryError = NewTemporaryError(nil) | ||
EOFError = NewEOFError(nil) | ||
) | ||
|
||
type Type uint8 | ||
|
||
func (t Type) String() string { | ||
switch t { | ||
case temporary: | ||
return "temporary" | ||
case eof: | ||
return "EOF" | ||
default: | ||
return "unknown" | ||
} | ||
} | ||
|
||
type syncError struct { | ||
t Type | ||
err error | ||
} | ||
|
||
func NewTemporaryError(err error) error { | ||
return &syncError{t: temporary, err: err} | ||
} | ||
|
||
func NewEOFError(err error) error { | ||
return &syncError{t: eof, err: err} | ||
} | ||
|
||
func (s *syncError) Error() string { | ||
return fmt.Sprintf("%s: %v", s.t, s.err) | ||
} | ||
|
||
func (s *syncError) Unwrap() error { | ||
return s.err | ||
} | ||
|
||
func (s *syncError) Is(target error) bool { | ||
if target == nil { | ||
return s == nil | ||
} | ||
|
||
targetSyncErr, ok := target.(*syncError) | ||
if !ok { | ||
return false | ||
} | ||
|
||
return s.t == targetSyncErr.t | ||
} | ||
|
||
func WrapWithTemporary(err error) error { | ||
return &syncError{ | ||
t: temporary, | ||
err: err, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters