@@ -17,8 +17,6 @@ import (
1717 "github.com/coder/websocket/internal/util"
1818)
1919
20- var ErrMessageTooBig = errors .New ("websocket: message too big" )
21-
2220// Reader reads from the connection until there is a WebSocket
2321// data message to be read. It will handle ping, pong and close frames as appropriate.
2422//
@@ -92,7 +90,8 @@ func (c *Conn) CloseRead(ctx context.Context) context.Context {
9290//
9391// By default, the connection has a message read limit of 32768 bytes.
9492//
95- // When the limit is hit, the connection will be closed with StatusMessageTooBig.
93+ // When the limit is hit, reads return an error wrapping ErrMessageTooBig and
94+ // the connection is closed with StatusMessageTooBig.
9695//
9796// Set to -1 to disable.
9897func (c * Conn ) SetReadLimit (n int64 ) {
@@ -522,9 +521,9 @@ func (lr *limitReader) Read(p []byte) (int, error) {
522521 }
523522
524523 if lr .n == 0 {
525- err := fmt .Errorf ("%w: %d bytes" , ErrMessageTooBig , lr .limit .Load ())
526- lr .c .writeError (StatusMessageTooBig , err )
527- return 0 , err
524+ reason := fmt .Errorf ("read limited at %d bytes" , lr .limit .Load ())
525+ lr .c .writeError (StatusMessageTooBig , reason )
526+ return 0 , fmt . Errorf ( "%w: %v" , ErrMessageTooBig , reason )
528527 }
529528
530529 if int64 (len (p )) > lr .n {
0 commit comments