-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherror.go
More file actions
88 lines (80 loc) · 2.02 KB
/
error.go
File metadata and controls
88 lines (80 loc) · 2.02 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
package dasmon
import (
"fmt"
)
// ErrKind represents the kind of sampling error that occurred
type ErrKind int
const (
ErrUnknown ErrKind = iota
ErrMissingSidecar
ErrInvalidRequest
ErrRPCFailure
ErrInvalidSidecar
ErrVerificationFailed
ErrInclusionProofInvalid
ErrCommitmentMismatch
ErrDuplicateSidecar
ErrCellCountMismatch
ErrProofCountMismatch
ErrUnexpectedSidecar
ErrTooManySidecars
ErrCommitmentMissing
ErrCommitmentCountMismatch
ErrNoCommitmentInfo
)
// String returns a human-readable string representation of the Err
func (k ErrKind) String() string {
switch k {
case ErrUnknown:
return "unknown"
case ErrInvalidRequest:
return "invalid_request"
case ErrRPCFailure:
return "rpc_failure"
case ErrInvalidSidecar:
return "invalid_sidecar"
case ErrVerificationFailed:
return "verification_failed"
case ErrInclusionProofInvalid:
return "inclusion_proof_invalid"
case ErrCommitmentMismatch:
return "commitment_mismatch"
case ErrDuplicateSidecar:
return "duplicate_sidecar"
case ErrCellCountMismatch:
return "length_mismatch"
case ErrUnexpectedSidecar:
return "slot_out_of_range"
case ErrTooManySidecars:
return "too_many_sidecars"
case ErrCommitmentMissing:
return "commitment_missing"
case ErrMissingSidecar:
return "missing_sidecar"
case ErrProofCountMismatch:
return "proof_count_mismatch"
case ErrCommitmentCountMismatch:
return "commitment_count_mismatch"
case ErrNoCommitmentInfo:
return "no_commitment_info"
default:
return fmt.Sprintf("unknown_error_kind_%d", k)
}
}
type DasmonError struct {
Kind ErrKind
Details string
Inner error
}
func NewError(kind ErrKind, format string, a ...any) error {
return DasmonError{kind, fmt.Sprintf(format, a...), nil}
}
func WrapError(kind ErrKind, inner error, format string, a ...any) error {
return DasmonError{kind, fmt.Sprintf(format, a...), inner}
}
func (de DasmonError) Error() string {
if de.Inner == nil {
return fmt.Sprintf("%s: %s", de.Kind, de.Details)
}
return fmt.Sprintf("%s: %s: %v", de.Kind, de.Details, de.Inner)
}