forked from decred/dcrd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
83 lines (66 loc) · 2.85 KB
/
error.go
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
// Copyright (c) 2019-2023 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package standalone
import "fmt"
// panicf is a convenience function that formats according to the given format
// specifier and arguments and panics with it.
func panicf(format string, args ...interface{}) {
str := fmt.Sprintf(format, args...)
panic(str)
}
// ErrorKind identifies a kind of error. It has full support for errors.Is and
// errors.As, so the caller can directly check against an error kind when
// determining the reason for an error.
type ErrorKind string
// These constants are used to identify a specific RuleError.
const (
// ErrUnexpectedDifficulty indicates specified bits do not align with
// the expected value either because it doesn't match the calculated
// value based on difficulty rules or it is out of the valid range.
ErrUnexpectedDifficulty = ErrorKind("ErrUnexpectedDifficulty")
// ErrHighHash indicates the block does not hash to a value which is
// lower than the required target difficultly.
ErrHighHash = ErrorKind("ErrHighHash")
// ErrInvalidTSpendExpiry indicates that an invalid expiry was
// provided when calculating the treasury spend voting window.
ErrInvalidTSpendExpiry = ErrorKind("ErrInvalidTSpendExpiry")
// ErrNoTxInputs indicates a transaction does not have any inputs. A valid
// transaction must have at least one input.
ErrNoTxInputs = ErrorKind("ErrNoTxInputs")
// ErrNoTxOutputs indicates a transaction does not have any outputs. A
// valid transaction must have at least one output.
ErrNoTxOutputs = ErrorKind("ErrNoTxOutputs")
// ErrTxTooBig indicates a transaction exceeds the maximum allowed size when
// serialized.
ErrTxTooBig = ErrorKind("ErrTxTooBig")
// ErrBadTxOutValue indicates an output value for a transaction is
// invalid in some way such as being out of range.
ErrBadTxOutValue = ErrorKind("ErrBadTxOutValue")
// ErrDuplicateTxInputs indicates a transaction references the same
// input more than once.
ErrDuplicateTxInputs = ErrorKind("ErrDuplicateTxInputs")
)
// Error satisfies the error interface and prints human-readable errors.
func (e ErrorKind) Error() string {
return string(e)
}
// RuleError identifies a rule violation. It has full support for errors.Is
// and errors.As, so the caller can ascertain the specific reason for the
// error by checking the underlying error.
type RuleError struct {
Description string
Err error
}
// Error satisfies the error interface and prints human-readable errors.
func (e RuleError) Error() string {
return e.Description
}
// Unwrap returns the underlying wrapped error.
func (e RuleError) Unwrap() error {
return e.Err
}
// ruleError creates a RuleError given a set of arguments.
func ruleError(kind ErrorKind, desc string) RuleError {
return RuleError{Err: kind, Description: desc}
}