• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 12312390362

13 Dec 2024 08:44AM UTC coverage: 57.458% (+8.5%) from 48.92%
12312390362

Pull #9343

github

ellemouton
fn: rework the ContextGuard and add tests

In this commit, the ContextGuard struct is re-worked such that the
context that its new main WithCtx method provides is cancelled in sync
with a parent context being cancelled or with it's quit channel being
cancelled. Tests are added to assert the behaviour. In order for the
close of the quit channel to be consistent with the cancelling of the
derived context, the quit channel _must_ be contained internal to the
ContextGuard so that callers are only able to close the channel via the
exposed Quit method which will then take care to first cancel any
derived context that depend on the quit channel before returning.
Pull Request #9343: fn: expand the ContextGuard and add tests

101853 of 177264 relevant lines covered (57.46%)

24972.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.21
/graph/errors.go
1
package graph
2

3
import "github.com/go-errors/errors"
4

5
// ErrorCode is used to represent the various errors that can occur within this
6
// package.
7
type ErrorCode uint8
8

9
const (
10
        // ErrOutdated is returned when the routing update already have
11
        // been applied, or a newer update is already known.
12
        ErrOutdated ErrorCode = iota
13

14
        // ErrIgnored is returned when the update have been ignored because
15
        // this update can't bring us something new, or because a node
16
        // announcement was given for node not found in any channel.
17
        ErrIgnored
18

19
        // ErrChannelSpent is returned when we go to validate a channel, but
20
        // the purported funding output has actually already been spent on
21
        // chain.
22
        ErrChannelSpent
23

24
        // ErrNoFundingTransaction is returned when we are unable to find the
25
        // funding transaction described by the short channel ID on chain.
26
        ErrNoFundingTransaction
27

28
        // ErrInvalidFundingOutput is returned if the channel funding output
29
        // fails validation.
30
        ErrInvalidFundingOutput
31

32
        // ErrVBarrierShuttingDown signals that the barrier has been requested
33
        // to shutdown, and that the caller should not treat the wait condition
34
        // as fulfilled.
35
        ErrVBarrierShuttingDown
36

37
        // ErrParentValidationFailed signals that the validation of a
38
        // dependent's parent failed, so the dependent must not be processed.
39
        ErrParentValidationFailed
40
)
41

42
// Error is a structure that represent the error inside the graph package,
43
// this structure carries additional information about error code in order to
44
// be able distinguish errors outside of the current package.
45
type Error struct {
46
        err  *errors.Error
47
        code ErrorCode
48
}
49

50
// Error represents errors as the string
51
// NOTE: Part of the error interface.
52
func (e *Error) Error() string {
×
53
        return e.err.Error()
×
54
}
×
55

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

59
// NewErrf creates a Error by the given error formatted description and
60
// its corresponding error code.
61
func NewErrf(code ErrorCode, format string, a ...interface{}) *Error {
213✔
62
        return &Error{
213✔
63
                code: code,
213✔
64
                err:  errors.Errorf(format, a...),
213✔
65
        }
213✔
66
}
213✔
67

68
// IsError is a helper function which is needed to have ability to check that
69
// returned error has specific error code.
70
func IsError(e interface{}, codes ...ErrorCode) bool {
623✔
71
        err, ok := e.(*Error)
623✔
72
        if !ok {
626✔
73
                return false
3✔
74
        }
3✔
75

76
        for _, code := range codes {
1,444✔
77
                if err.code == code {
1,239✔
78
                        return true
415✔
79
                }
415✔
80
        }
81

82
        return false
205✔
83
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc