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

lightningnetwork / lnd / 19153182187

06 Nov 2025 11:36PM UTC coverage: 54.793% (-11.9%) from 66.712%
19153182187

Pull #10352

github

web-flow
Merge d6c3e8fa9 into 096ab65b1
Pull Request #10352: [WIP] chainrpc: return Unavailable while notifier starts

110400 of 201486 relevant lines covered (54.79%)

21823.7 hits per line

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

67.44
/lnwire/error.go
1
package lnwire
2

3
import (
4
        "bytes"
5
        "fmt"
6
        "io"
7
)
8

9
var (
10
        // ErrParsingExtraTLVBytes is returned when we attempt to parse
11
        // extra opaque bytes as a TLV stream, but the parsing fails due to
12
        // and invalid TLV stream.
13
        ErrParsingExtraTLVBytes = fmt.Errorf("error parsing extra TLV bytes")
14
)
15

16
// FundingError represents a set of errors that can be encountered and sent
17
// during the funding workflow.
18
type FundingError uint8
19

20
const (
21
        // ErrMaxPendingChannels is returned by remote peer when the number of
22
        // active pending channels exceeds their maximum policy limit.
23
        ErrMaxPendingChannels FundingError = 1
24

25
        // ErrChanTooLarge is returned by a remote peer that receives a
26
        // FundingOpen request for a channel that is above their current
27
        // soft-limit.
28
        ErrChanTooLarge FundingError = 2
29
)
30

31
// String returns a human readable version of the target FundingError.
32
func (e FundingError) String() string {
4✔
33
        switch e {
4✔
34
        case ErrMaxPendingChannels:
4✔
35
                return "Number of pending channels exceed maximum"
4✔
36
        case ErrChanTooLarge:
×
37
                return "channel too large"
×
38
        default:
×
39
                return "unknown error"
×
40
        }
41
}
42

43
// Error returns the human readable version of the target FundingError.
44
//
45
// NOTE: Satisfies the Error interface.
46
func (e FundingError) Error() string {
4✔
47
        return e.String()
4✔
48
}
4✔
49

50
// ErrorData is a set of bytes associated with a particular sent error. A
51
// receiving node SHOULD only print out data verbatim if the string is composed
52
// solely of printable ASCII characters. For reference, the printable character
53
// set includes byte values 32 through 127 inclusive.
54
type ErrorData []byte
55

56
// Error represents a generic error bound to an exact channel. The message
57
// format is purposefully general in order to allow expression of a wide array
58
// of possible errors. Each Error message is directed at a particular open
59
// channel referenced by ChannelPoint.
60
type Error struct {
61
        // ChanID references the active channel in which the error occurred
62
        // within. If the ChanID is all zeros, then this error applies to the
63
        // entire established connection.
64
        ChanID ChannelID
65

66
        // Data is the attached error data that describes the exact failure
67
        // which caused the error message to be sent.
68
        Data ErrorData
69
}
70

71
// NewError creates a new Error message.
72
func NewError() *Error {
×
73
        return &Error{}
×
74
}
×
75

76
// A compile time check to ensure Error implements the lnwire.Message
77
// interface.
78
var _ Message = (*Error)(nil)
79

80
// A compile time check to ensure Error implements the lnwire.SizeableMessage
81
// interface.
82
var _ SizeableMessage = (*Error)(nil)
83

84
// Error returns the string representation to Error.
85
//
86
// NOTE: Satisfies the error interface.
87
func (c *Error) Error() string {
35✔
88
        errMsg := "non-ascii data"
35✔
89
        if isASCII(c.Data) {
70✔
90
                errMsg = string(c.Data)
35✔
91
        }
35✔
92

93
        return fmt.Sprintf("chan_id=%v, err=%v", c.ChanID, errMsg)
35✔
94
}
95

96
// Decode deserializes a serialized Error message stored in the passed
97
// io.Reader observing the specified protocol version.
98
//
99
// This is part of the lnwire.Message interface.
100
func (c *Error) Decode(r io.Reader, pver uint32) error {
113✔
101
        return ReadElements(r,
113✔
102
                &c.ChanID,
113✔
103
                &c.Data,
113✔
104
        )
113✔
105
}
113✔
106

107
// Encode serializes the target Error into the passed io.Writer observing the
108
// protocol version specified.
109
//
110
// This is part of the lnwire.Message interface.
111
func (c *Error) Encode(w *bytes.Buffer, pver uint32) error {
105✔
112
        if err := WriteBytes(w, c.ChanID[:]); err != nil {
105✔
113
                return err
×
114
        }
×
115

116
        return WriteErrorData(w, c.Data)
105✔
117
}
118

119
// MsgType returns the integer uniquely identifying an Error message on the
120
// wire.
121
//
122
// This is part of the lnwire.Message interface.
123
func (c *Error) MsgType() MessageType {
106✔
124
        return MsgError
106✔
125
}
106✔
126

127
// SerializedSize returns the serialized size of the message in bytes.
128
//
129
// This is part of the lnwire.SizeableMessage interface.
130
func (c *Error) SerializedSize() (uint32, error) {
×
131
        return MessageSerializedSize(c)
×
132
}
×
133

134
// isASCII is a helper method that checks whether all bytes in `data` would be
135
// printable ASCII characters if interpreted as a string.
136
func isASCII(data []byte) bool {
80✔
137
        for _, c := range data {
823✔
138
                if c < 32 || c > 126 {
743✔
139
                        return false
×
140
                }
×
141
        }
142
        return true
80✔
143
}
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