Repository navigation
Expand file tree
/
Copy patherrors.go
More file actions
93 lines (82 loc) · 2.5 KB
/
Copy patherrors.go
File metadata and controls
93 lines (82 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package bedrock
import "fmt"
// ErrorKind categorizes every failure a Bedrock client can surface. The
// vocabulary is identical across all official System Locker libraries.
type ErrorKind uint8
const (
// ErrConfiguration means the local configuration is invalid. No request
// was sent.
ErrConfiguration ErrorKind = iota
// ErrTransport means the HTTP exchange itself failed or returned a
// non-2xx status.
ErrTransport
// ErrUnsignedResponse means the response lacked its signed transport
// headers and is not the one permitted unsigned revocation.
ErrUnsignedResponse
// ErrInvalidSignature means Ed25519 verification against the pinned
// public key failed.
ErrInvalidSignature
// ErrInvalidPayload means the response was signed but its contents are
// inconsistent with the protocol or this request.
ErrInvalidPayload
// ErrFreshnessViolation means server_time is outside the configured
// clock-skew window.
ErrFreshnessViolation
// ErrSessionTerminated means the session ended, by the server or
// locally.
ErrSessionTerminated
// ErrLocalFailure covers local runtime failures (I/O, CSPRNG, clock).
ErrLocalFailure
)
func (k ErrorKind) String() string {
switch k {
case ErrConfiguration:
return "Configuration"
case ErrTransport:
return "Transport"
case ErrUnsignedResponse:
return "UnsignedResponse"
case ErrInvalidSignature:
return "InvalidSignature"
case ErrInvalidPayload:
return "InvalidPayload"
case ErrFreshnessViolation:
return "FreshnessViolation"
case ErrSessionTerminated:
return "SessionTerminated"
case ErrLocalFailure:
return "LocalFailure"
default:
return "LocalFailure"
}
}
// Error is the error type returned by every client operation.
type Error struct {
Kind ErrorKind
Message string
}
func (e *Error) Error() string { return e.Message }
func fail(kind ErrorKind, format string, args ...any) *Error {
return &Error{Kind: kind, Message: fmt.Sprintf(format, args...)}
}
// asError coerces a non-nil error into *Error, wrapping unknown errors as
// LocalFailure.
func asError(err error) *Error {
if err == nil {
return nil
}
if bedrockErr, ok := err.(*Error); ok {
return bedrockErr
}
return &Error{Kind: ErrLocalFailure, Message: err.Error()}
}
// JSONError is the error produced when a payload field is missing or has the
// wrong type.
type JSONError struct {
Field string
}
func (e *JSONError) Error() string {
return "Bedrock field '" + e.Field + "' is missing or has the wrong type."
}
var _ error = (*JSONError)(nil)
var _ error = (*Error)(nil)