From 15c54e80dec3e577384b1dfd4364759ab40c8e63 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Mon, 3 Aug 2020 23:44:44 -0400 Subject: [PATCH] clean up some error handling --- irc/errors.go | 7 ------- irc/ircconn.go | 9 +++++++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/irc/errors.go b/irc/errors.go index 01758997..5e3efc74 100644 --- a/irc/errors.go +++ b/irc/errors.go @@ -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") diff --git a/irc/ircconn.go b/irc/ircconn.go index 9ddb0da7..c0ffb948 100644 --- a/irc/ircconn.go +++ b/irc/ircconn.go @@ -3,6 +3,7 @@ package irc import ( "bufio" "bytes" + "errors" "net" "unicode/utf8" @@ -17,7 +18,8 @@ const ( ) var ( - crlf = []byte{'\r', '\n'} + 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 } }