3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

clean up some error handling

This commit is contained in:
Shivaram Lingamneni 2020-08-03 23:44:44 -04:00
parent daefa40b75
commit 15c54e80de
2 changed files with 7 additions and 9 deletions

View File

@ -73,13 +73,6 @@ var (
errRegisteredOnly = errors.New("Cannot join registered-only channel without an account")
)
// Socket Errors
var (
errNoPeerCerts = errors.New("Client did not provide a certificate")
errNotTLS = errors.New("Not a TLS connection")
errReadQ = errors.New("ReadQ Exceeded")
)
// String Errors
var (
errCouldNotStabilize = errors.New("Could not stabilize string while casefolding")

View File

@ -3,6 +3,7 @@ package irc
import (
"bufio"
"bytes"
"errors"
"net"
"unicode/utf8"
@ -18,6 +19,7 @@ const (
var (
crlf = []byte{'\r', '\n'}
errReadQ = errors.New("ReadQ Exceeded")
)
// IRCConn abstracts away the distinction between a regular
@ -31,7 +33,7 @@ type IRCConn interface {
// these take an IRC line or lines, correctly terminated with CRLF:
WriteLine([]byte) error
WriteLines([][]byte) error
// this returns an IRC line without the terminating CRLF:
// this returns an IRC line, possibly terminated with CRLF, LF, or nothing:
ReadLine() (line []byte, err error)
Close() error
@ -127,6 +129,9 @@ func (wc IRCWSConn) ReadLine() (line []byte, err error) {
messageType, line, err = wc.conn.ReadMessage()
// on empty message or non-text message, try again, block if necessary
if err != nil || (messageType == websocket.TextMessage && len(line) != 0) {
if err == websocket.ErrReadLimit {
err = errReadQ
}
return
}
}