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

lightningnetwork / lnd / 15561477203

10 Jun 2025 01:54PM UTC coverage: 58.351% (-10.1%) from 68.487%
15561477203

Pull #9356

github

web-flow
Merge 6440b25db into c6d6d4c0b
Pull Request #9356: lnrpc: add incoming/outgoing channel ids filter to forwarding history request

33 of 36 new or added lines in 2 files covered. (91.67%)

28366 existing lines in 455 files now uncovered.

97715 of 167461 relevant lines covered (58.35%)

1.81 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
// FundingError represents a set of errors that can be encountered and sent
10
// during the funding workflow.
11
type FundingError uint8
12

13
const (
14
        // ErrMaxPendingChannels is returned by remote peer when the number of
15
        // active pending channels exceeds their maximum policy limit.
16
        ErrMaxPendingChannels FundingError = 1
17

18
        // ErrChanTooLarge is returned by a remote peer that receives a
19
        // FundingOpen request for a channel that is above their current
20
        // soft-limit.
21
        ErrChanTooLarge FundingError = 2
22
)
23

24
// String returns a human readable version of the target FundingError.
25
func (e FundingError) String() string {
3✔
26
        switch e {
3✔
27
        case ErrMaxPendingChannels:
3✔
28
                return "Number of pending channels exceed maximum"
3✔
29
        case ErrChanTooLarge:
×
30
                return "channel too large"
×
31
        default:
×
32
                return "unknown error"
×
33
        }
34
}
35

36
// Error returns the human readable version of the target FundingError.
37
//
38
// NOTE: Satisfies the Error interface.
39
func (e FundingError) Error() string {
3✔
40
        return e.String()
3✔
41
}
3✔
42

43
// ErrorData is a set of bytes associated with a particular sent error. A
44
// receiving node SHOULD only print out data verbatim if the string is composed
45
// solely of printable ASCII characters. For reference, the printable character
46
// set includes byte values 32 through 127 inclusive.
47
type ErrorData []byte
48

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

59
        // Data is the attached error data that describes the exact failure
60
        // which caused the error message to be sent.
61
        Data ErrorData
62
}
63

64
// NewError creates a new Error message.
65
func NewError() *Error {
×
66
        return &Error{}
×
67
}
×
68

69
// A compile time check to ensure Error implements the lnwire.Message
70
// interface.
71
var _ Message = (*Error)(nil)
72

73
// A compile time check to ensure Error implements the lnwire.SizeableMessage
74
// interface.
75
var _ SizeableMessage = (*Error)(nil)
76

77
// Error returns the string representation to Error.
78
//
79
// NOTE: Satisfies the error interface.
80
func (c *Error) Error() string {
3✔
81
        errMsg := "non-ascii data"
3✔
82
        if isASCII(c.Data) {
6✔
83
                errMsg = string(c.Data)
3✔
84
        }
3✔
85

86
        return fmt.Sprintf("chan_id=%v, err=%v", c.ChanID, errMsg)
3✔
87
}
88

89
// Decode deserializes a serialized Error message stored in the passed
90
// io.Reader observing the specified protocol version.
91
//
92
// This is part of the lnwire.Message interface.
93
func (c *Error) Decode(r io.Reader, pver uint32) error {
3✔
94
        return ReadElements(r,
3✔
95
                &c.ChanID,
3✔
96
                &c.Data,
3✔
97
        )
3✔
98
}
3✔
99

100
// Encode serializes the target Error into the passed io.Writer observing the
101
// protocol version specified.
102
//
103
// This is part of the lnwire.Message interface.
104
func (c *Error) Encode(w *bytes.Buffer, pver uint32) error {
3✔
105
        if err := WriteBytes(w, c.ChanID[:]); err != nil {
3✔
106
                return err
×
107
        }
×
108

109
        return WriteErrorData(w, c.Data)
3✔
110
}
111

112
// MsgType returns the integer uniquely identifying an Error message on the
113
// wire.
114
//
115
// This is part of the lnwire.Message interface.
116
func (c *Error) MsgType() MessageType {
3✔
117
        return MsgError
3✔
118
}
3✔
119

120
// SerializedSize returns the serialized size of the message in bytes.
121
//
122
// This is part of the lnwire.SizeableMessage interface.
UNCOV
123
func (c *Error) SerializedSize() (uint32, error) {
×
UNCOV
124
        return MessageSerializedSize(c)
×
UNCOV
125
}
×
126

127
// isASCII is a helper method that checks whether all bytes in `data` would be
128
// printable ASCII characters if interpreted as a string.
129
func isASCII(data []byte) bool {
3✔
130
        for _, c := range data {
6✔
131
                if c < 32 || c > 126 {
3✔
132
                        return false
×
133
                }
×
134
        }
135
        return true
3✔
136
}
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