Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion read.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"github.com/coder/websocket/internal/util"
)

var ErrMessageTooBig = errors.New("websocket: message too big")

// Reader reads from the connection until there is a WebSocket
// data message to be read. It will handle ping, pong and close frames as appropriate.
//
Expand Down Expand Up @@ -520,7 +522,7 @@ func (lr *limitReader) Read(p []byte) (int, error) {
}

if lr.n == 0 {
err := fmt.Errorf("read limited at %v bytes", lr.limit.Load())
err := fmt.Errorf("%w: %d bytes", ErrMessageTooBig, lr.limit.Load())
lr.c.writeError(StatusMessageTooBig, err)
return 0, err
}
Expand Down
4 changes: 3 additions & 1 deletion ws_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"github.com/coder/websocket/internal/wsjs"
)

var ErrMessageTooBig = errors.New("websocket: message too big")

// opcode represents a WebSocket opcode.
type opcode int

Expand Down Expand Up @@ -144,7 +146,7 @@ func (c *Conn) Read(ctx context.Context) (MessageType, []byte, error) {
}
readLimit := c.msgReadLimit.Load()
if readLimit >= 0 && int64(len(p)) > readLimit {
err := fmt.Errorf("read limited at %v bytes", c.msgReadLimit.Load())
err := fmt.Errorf("%w: %d bytes", ErrMessageTooBig, c.msgReadLimit.Load())
c.Close(StatusMessageTooBig, err.Error())
return 0, nil, err
}
Expand Down