This repository has been archived by the owner on Nov 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.go
153 lines (121 loc) · 4.34 KB
/
errors.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* Copyright 2021 Aletheia Ware LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package bcgo
import "fmt"
// ErrBlockHashIncorrect is returned when the given hash does not match the hash of the given block.
type ErrBlockHashIncorrect struct {
}
func (e ErrBlockHashIncorrect) Error() string {
return "Hash doesn't match block hash"
}
// ErrChainInvalid is returned when a block fails validation for some reason.
type ErrChainInvalid struct {
Reason string
}
func (e ErrChainInvalid) Error() string {
return fmt.Sprintf("Chain invalid: %s", e.Reason)
}
// ErrChainTooShort is returned when a new chain is shorter the channel's current head.
type ErrChainTooShort struct {
LengthA, LengthB uint64
}
func (e ErrChainTooShort) Error() string {
return fmt.Sprintf("Chain too short to replace current head: %d vs %d", e.LengthA, e.LengthB)
}
// ErrChannelNameIncorrect is returned when a block channel name doesn't match the channel.
type ErrChannelNameIncorrect struct {
Expected, Actual string
}
func (e ErrChannelNameIncorrect) Error() string {
return fmt.Sprintf("Name doesn't match channel name: %s vs %s", e.Expected, e.Actual)
}
// ErrChannelNameInvalid is returned when a channel name is too long or includes unsupported characters.
type ErrChannelNameInvalid struct {
Reason string
}
func (e ErrChannelNameInvalid) Error() string {
return fmt.Sprintf("Name invalid: %s", e.Reason)
}
// ErrChannelOutOfDate is returned when a broadcast fails due to the network
// having a more up-to-date version of the channel.
type ErrChannelOutOfDate struct {
Channel string
}
func (e ErrChannelOutOfDate) Error() string {
return fmt.Sprintf("Channel out of date: %s", e.Channel)
}
// ErrBlockTooLarge is returned when the Block exceeds the size limit.
type ErrBlockTooLarge struct {
Size, Max uint64
}
func (e ErrBlockTooLarge) Error() string {
return fmt.Sprintf("Block too large: %s max: %s", BinarySizeToString(e.Size), BinarySizeToString(e.Max))
}
// ErrPayloadTooLarge is returned when the Payload exceeds the size limit.
type ErrPayloadTooLarge struct {
Size, Max uint64
}
func (e ErrPayloadTooLarge) Error() string {
return fmt.Sprintf("Payload too large: %s max: %s", BinarySizeToString(e.Size), BinarySizeToString(e.Max))
}
// ErrNoSuchChannel is returned when a channel with the given name cannot be found.
type ErrNoSuchChannel struct {
Channel string
}
func (e ErrNoSuchChannel) Error() string {
return fmt.Sprintf("No such channel: %s", e.Channel)
}
// ErrNoSuchBlock is returned when a block with the given hash cannot be found.
type ErrNoSuchBlock struct {
Hash string
}
func (e ErrNoSuchBlock) Error() string {
return fmt.Sprintf("No such block: %s", e.Hash)
}
// ErrNoSuchHead is returned when a head with the given name cannot be found.
type ErrNoSuchHead struct {
Channel string
}
func (e ErrNoSuchHead) Error() string {
return fmt.Sprintf("No such head: %s", e.Channel)
}
// ErrNoSuchMapping is returned when a mapping with the given hash cannot be found.
type ErrNoSuchMapping struct {
Hash string
}
func (e ErrNoSuchMapping) Error() string {
return fmt.Sprintf("No such record to block mapping: %s", e.Hash)
}
// ErrNoEntriesToMine is returned when a mining operation fails due to a lack of entries.
type ErrNoEntriesToMine struct {
Channel string
}
func (e ErrNoEntriesToMine) Error() string {
return fmt.Sprintf("No entries to mine for channel: %s", e.Channel)
}
// ErrNonceWrapAround is returned when a mining operation fails after attempting every possible nonce.
type ErrNonceWrapAround struct {
}
func (e ErrNonceWrapAround) Error() string {
return "Nonce wrapped around before reaching threshold"
}
// ErrStopIteration is used by callbacks to indicate that their iteration
// through a channel should stop, typically because the result has been found.
type ErrStopIteration struct {
}
func (e ErrStopIteration) Error() string {
return "Stop Iteration"
}