Skip to content

Commit 1f18f65

Browse files
committed
more specific submission errors
1 parent 9af068f commit 1f18f65

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ func (c *Config) valid() error {
168168
return nil
169169
}
170170

171-
// NewCONNREQ returns a new packet.
172-
func (c *Config) newCONNREQ(clientID []byte) []byte {
171+
// NewConnectReq returns a new CONNECT packet conform the configuration.
172+
func (c *Config) newConnectReq(clientID []byte) []byte {
173173
size := 12 + len(clientID)
174174
var flags uint
175175

@@ -1044,9 +1044,9 @@ func (c *Client) resend(conn net.Conn, seqNoOffset uint, seq *seq, space uint) e
10441044

10451045
func (c *Client) handshake(conn net.Conn, config *Config, clientID []byte) (*bufio.Reader, error) {
10461046
// send request
1047-
err := writeTo(conn, config.newCONNREQ(clientID), c.PauseTimeout)
1047+
err := writeTo(conn, config.newConnectReq(clientID), c.PauseTimeout)
10481048
if err != nil {
1049-
return nil, err
1049+
return nil, fmt.Errorf("mqtt: connection fatal during CONNECT submission; %w", err)
10501050
}
10511051

10521052
r := bufio.NewReaderSize(conn, readBufSize)

mqtt_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestErrorClasses(t *testing.T) {
5555
}
5656
}
5757

58-
func TestNewCONNREQ(t *testing.T) {
58+
func TestNewConnectReq(t *testing.T) {
5959
c := &Config{
6060
Dialer: func(context.Context) (net.Conn, error) {
6161
return nil, errors.New("dialer call not allowed for test")
@@ -71,7 +71,7 @@ func TestNewCONNREQ(t *testing.T) {
7171
c.Will.AtLeastOnce = true
7272
c.Will.ExactlyOnce = true
7373

74-
got := c.newCONNREQ([]byte("#🤖"))
74+
got := c.newConnectReq([]byte("#🤖"))
7575
want := []byte{0x10, 37, 0, 4, 'M', 'Q', 'T', 'T', 4, 0b1111_0110, 0x0e, 0x10,
7676
0, 5, '#', 0xF0, 0x9F, 0xA4, 0x96,
7777
0, 6, 0xe2, 0x98, 0xaf, 0xef, 0xb8, 0x8f,

request.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ var ErrAbandoned = errors.New("mqtt: request abandoned after submission")
2828
// status of the execution remains unknown, because there is no telling how much
2929
// of the payload actually reached the broker. Connection loss after submision
3030
// causes ErrBreak instead.
31-
var ErrSubmit = errors.New("mqtt: connection lost during submission")
31+
var ErrSubmit = errors.New("mqtt: connection fatal during submission")
3232

3333
// ErrBreak signals that the connection was lost after a request was send, and
3434
// before a response was received. The status of the execution remains unknown,
3535
// similar to ErrSubmit.
36-
var ErrBreak = errors.New("mqtt: connection lost while awaiting response")
36+
var ErrBreak = errors.New("mqtt: connection fatal while awaiting response")
3737

3838
// BufSize should fit topic names with a bit of overhead.
3939
const bufSize = 128

0 commit comments

Comments
 (0)