Skip to content

Commit ae33b76

Browse files
Crypt-iQRoasbeef
authored andcommitted
graph: export NewErrf and ErrorCode for upcoming gossiper unit tests
1 parent de58e3e commit ae33b76

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

graph/builder.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ func (b *Builder) handleNetworkUpdate(vb *ValidationBarrier,
681681
update.err <- err
682682

683683
case IsError(err, ErrParentValidationFailed):
684-
update.err <- newErrf(ErrIgnored, err.Error())
684+
update.err <- NewErrf(ErrIgnored, err.Error()) //nolint
685685

686686
default:
687687
log.Warnf("unexpected error during validation "+
@@ -1053,7 +1053,7 @@ func (b *Builder) assertNodeAnnFreshness(node route.Vertex,
10531053
"existence of node: %v", err)
10541054
}
10551055
if !exists {
1056-
return newErrf(ErrIgnored, "Ignoring node announcement"+
1056+
return NewErrf(ErrIgnored, "Ignoring node announcement"+
10571057
" for node not found in channel graph (%x)",
10581058
node[:])
10591059
}
@@ -1063,7 +1063,7 @@ func (b *Builder) assertNodeAnnFreshness(node route.Vertex,
10631063
// if not then we won't accept the new data as it would override newer
10641064
// data.
10651065
if !lastUpdate.Before(msgTimestamp) {
1066-
return newErrf(ErrOutdated, "Ignoring outdated "+
1066+
return NewErrf(ErrOutdated, "Ignoring outdated "+
10671067
"announcement for %x", node[:])
10681068
}
10691069

@@ -1193,11 +1193,11 @@ func (b *Builder) processUpdate(msg interface{},
11931193
"existence: %v", err)
11941194
}
11951195
if isZombie {
1196-
return newErrf(ErrIgnored, "ignoring msg for zombie "+
1196+
return NewErrf(ErrIgnored, "ignoring msg for zombie "+
11971197
"chan_id=%v", msg.ChannelID)
11981198
}
11991199
if exists {
1200-
return newErrf(ErrIgnored, "ignoring msg for known "+
1200+
return NewErrf(ErrIgnored, "ignoring msg for known "+
12011201
"chan_id=%v", msg.ChannelID)
12021202
}
12031203

@@ -1259,7 +1259,7 @@ func (b *Builder) processUpdate(msg interface{},
12591259
default:
12601260
}
12611261

1262-
return newErrf(ErrNoFundingTransaction, "unable to "+
1262+
return NewErrf(ErrNoFundingTransaction, "unable to "+
12631263
"locate funding tx: %v", err)
12641264
}
12651265

@@ -1294,7 +1294,7 @@ func (b *Builder) processUpdate(msg interface{},
12941294
return err
12951295
}
12961296

1297-
return newErrf(ErrInvalidFundingOutput, "output "+
1297+
return NewErrf(ErrInvalidFundingOutput, "output "+
12981298
"failed validation: %w", err)
12991299
}
13001300

@@ -1313,7 +1313,7 @@ func (b *Builder) processUpdate(msg interface{},
13131313
}
13141314
}
13151315

1316-
return newErrf(ErrChannelSpent, "unable to fetch utxo "+
1316+
return NewErrf(ErrChannelSpent, "unable to fetch utxo "+
13171317
"for chan_id=%v, chan_point=%v: %v",
13181318
msg.ChannelID, fundingPoint, err)
13191319
}
@@ -1378,7 +1378,7 @@ func (b *Builder) processUpdate(msg interface{},
13781378
b.cfg.ChannelPruneExpiry
13791379

13801380
if isZombie && isStaleUpdate {
1381-
return newErrf(ErrIgnored, "ignoring stale update "+
1381+
return NewErrf(ErrIgnored, "ignoring stale update "+
13821382
"(flags=%v|%v) for zombie chan_id=%v",
13831383
msg.MessageFlags, msg.ChannelFlags,
13841384
msg.ChannelID)
@@ -1387,7 +1387,7 @@ func (b *Builder) processUpdate(msg interface{},
13871387
// If the channel doesn't exist in our database, we cannot
13881388
// apply the updated policy.
13891389
if !exists {
1390-
return newErrf(ErrIgnored, "ignoring update "+
1390+
return NewErrf(ErrIgnored, "ignoring update "+
13911391
"(flags=%v|%v) for unknown chan_id=%v",
13921392
msg.MessageFlags, msg.ChannelFlags,
13931393
msg.ChannelID)
@@ -1405,7 +1405,7 @@ func (b *Builder) processUpdate(msg interface{},
14051405

14061406
// Ignore outdated message.
14071407
if !edge1Timestamp.Before(msg.LastUpdate) {
1408-
return newErrf(ErrOutdated, "Ignoring "+
1408+
return NewErrf(ErrOutdated, "Ignoring "+
14091409
"outdated update (flags=%v|%v) for "+
14101410
"known chan_id=%v", msg.MessageFlags,
14111411
msg.ChannelFlags, msg.ChannelID)
@@ -1417,7 +1417,7 @@ func (b *Builder) processUpdate(msg interface{},
14171417

14181418
// Ignore outdated message.
14191419
if !edge2Timestamp.Before(msg.LastUpdate) {
1420-
return newErrf(ErrOutdated, "Ignoring "+
1420+
return NewErrf(ErrOutdated, "Ignoring "+
14211421
"outdated update (flags=%v|%v) for "+
14221422
"known chan_id=%v", msg.MessageFlags,
14231423
msg.ChannelFlags, msg.ChannelID)

graph/builder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ func newChannelEdgeInfo(t *testing.T, ctx *testCtx, fundingHeight uint32,
12751275
}
12761276

12771277
func assertChanChainRejection(t *testing.T, ctx *testCtx,
1278-
edge *models.ChannelEdgeInfo, failCode errorCode) {
1278+
edge *models.ChannelEdgeInfo, failCode ErrorCode) {
12791279

12801280
t.Helper()
12811281

graph/errors.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package graph
22

33
import "github.com/go-errors/errors"
44

5-
// errorCode is used to represent the various errors that can occur within this
5+
// ErrorCode is used to represent the various errors that can occur within this
66
// package.
7-
type errorCode uint8
7+
type ErrorCode uint8
88

99
const (
1010
// ErrOutdated is returned when the routing update already have
1111
// been applied, or a newer update is already known.
12-
ErrOutdated errorCode = iota
12+
ErrOutdated ErrorCode = iota
1313

1414
// ErrIgnored is returned when the update have been ignored because
1515
// this update can't bring us something new, or because a node
@@ -39,36 +39,36 @@ const (
3939
ErrParentValidationFailed
4040
)
4141

42-
// graphError is a structure that represent the error inside the graph package,
42+
// Error is a structure that represent the error inside the graph package,
4343
// this structure carries additional information about error code in order to
4444
// be able distinguish errors outside of the current package.
45-
type graphError struct {
45+
type Error struct {
4646
err *errors.Error
47-
code errorCode
47+
code ErrorCode
4848
}
4949

5050
// Error represents errors as the string
5151
// NOTE: Part of the error interface.
52-
func (e *graphError) Error() string {
52+
func (e *Error) Error() string {
5353
return e.err.Error()
5454
}
5555

56-
// A compile time check to ensure graphError implements the error interface.
57-
var _ error = (*graphError)(nil)
56+
// A compile time check to ensure Error implements the error interface.
57+
var _ error = (*Error)(nil)
5858

59-
// newErrf creates a graphError by the given error formatted description and
59+
// NewErrf creates a Error by the given error formatted description and
6060
// its corresponding error code.
61-
func newErrf(code errorCode, format string, a ...interface{}) *graphError {
62-
return &graphError{
61+
func NewErrf(code ErrorCode, format string, a ...interface{}) *Error {
62+
return &Error{
6363
code: code,
6464
err: errors.Errorf(format, a...),
6565
}
6666
}
6767

6868
// IsError is a helper function which is needed to have ability to check that
6969
// returned error has specific error code.
70-
func IsError(e interface{}, codes ...errorCode) bool {
71-
err, ok := e.(*graphError)
70+
func IsError(e interface{}, codes ...ErrorCode) bool {
71+
err, ok := e.(*Error)
7272
if !ok {
7373
return false
7474
}

graph/validation_barrier.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,12 @@ func (v *ValidationBarrier) WaitForDependants(job interface{}) error {
238238
// is closed, or the set of jobs exits.
239239
select {
240240
case <-v.quit:
241-
return newErrf(ErrVBarrierShuttingDown,
241+
return NewErrf(ErrVBarrierShuttingDown,
242242
"validation barrier shutting down")
243243

244244
case <-signals.deny:
245245
log.Debugf("Signal deny for %s", jobDesc)
246-
return newErrf(ErrParentValidationFailed,
246+
return NewErrf(ErrParentValidationFailed,
247247
"parent validation failed")
248248

249249
case <-signals.allow:

0 commit comments

Comments
 (0)