Skip to content

Commit

Permalink
Re-enable errcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
belak committed Sep 22, 2021
1 parent 9c30bfc commit b93c7df
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 23 deletions.
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ linters:
disable:
- gochecknoglobals
- gomnd
- nlreturn
# TODO: re-enable these
- errcheck
- funlen
- testpackage
# TODO: maybe re-enable these
- godox
- wsl
- exhaustivestruct
- nlreturn
- predeclared
- ifshort
# TODO: there seems to be a false positive here
Expand Down
48 changes: 36 additions & 12 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ func (c *Client) maybeStartPingLoop(wg *sync.WaitGroup, exiting chan struct{}) {
func (c *Client) handlePing(timestamp int64, pongChan chan struct{}, wg *sync.WaitGroup, exiting chan struct{}) {
defer wg.Done()

c.Writef("PING :%d", timestamp)
err := c.Writef("PING :%d", timestamp)
if err != nil {
c.sendError(err)
return
}

timer := time.NewTimer(c.config.PingTimeout)
defer timer.Stop()
Expand All @@ -212,19 +216,28 @@ func (c *Client) handlePing(timestamp int64, pongChan chan struct{}, wg *sync.Wa

// maybeStartCapHandshake will run a CAP LS and all the relevant CAP REQ
// commands if there are any CAPs requested.
func (c *Client) maybeStartCapHandshake() {
func (c *Client) maybeStartCapHandshake() error {
if len(c.caps) == 0 {
return
return nil
}

err := c.Write("CAP LS")
if err != nil {
return err
}

c.Write("CAP LS")
c.remainingCapResponses = 1 // We count the CAP LS response as a normal response
for key, cap := range c.caps {
if cap.Requested {
c.Writef("CAP REQ :%s", key)
err = c.Writef("CAP REQ :%s", key)
if err != nil {
return err
}
c.remainingCapResponses++
}
}

return nil
}

// CapRequest allows you to request IRCv3 capabilities from the server during
Expand Down Expand Up @@ -282,11 +295,11 @@ func (c *Client) startReadLoop(wg *sync.WaitGroup, exiting chan struct{}) {
}

if c.ISupport != nil {
c.ISupport.Handle(m)
_ = c.ISupport.Handle(m)
}

if c.Tracker != nil {
c.Tracker.Handle(m)
_ = c.Tracker.Handle(m)
}

if c.config.Handler != nil {
Expand Down Expand Up @@ -316,23 +329,34 @@ func (c *Client) RunContext(ctx context.Context) error {
c.maybeStartPingLoop(&wg, exiting)

if c.config.Pass != "" {
c.Writef("PASS :%s", c.config.Pass)
err := c.Writef("PASS :%s", c.config.Pass)
if err != nil {
return err
}
}

c.maybeStartCapHandshake()
err := c.maybeStartCapHandshake()
if err != nil {
return err
}

// This feels wrong because it results in CAP LS, CAP REQ, NICK, USER, CAP
// END, but it works and lets us keep the code a bit simpler.
c.Writef("NICK :%s", c.config.Nick)
c.Writef("USER %s 0 * :%s", c.config.User, c.config.Name)
err = c.Writef("NICK :%s", c.config.Nick)
if err != nil {
return err
}
err = c.Writef("USER %s 0 * :%s", c.config.User, c.config.Name)
if err != nil {
return err
}

// Now that the handshake is pretty much done, we can start listening for
// messages.
c.startReadLoop(&wg, exiting)

// Wait for an error from any goroutine or for the context to time out, then
// signal we're exiting and wait for the goroutines to exit.
var err error
select {
case err = <-c.errChan:
case <-ctx.Done():
Expand Down
8 changes: 4 additions & 4 deletions client_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func handle433(c *Client, m *Message) {
return
}
c.currentNick += "_"
c.Writef("NICK :%s", c.currentNick)
_ = c.Writef("NICK :%s", c.currentNick)
}

// From rfc2812 section 5.2 (Error Replies)
Expand All @@ -66,13 +66,13 @@ func handle437(c *Client, m *Message) {
return
}
c.currentNick += "_"
c.Writef("NICK :%s", c.currentNick)
_ = c.Writef("NICK :%s", c.currentNick)
}

func handlePing(c *Client, m *Message) {
reply := m.Copy()
reply.Command = "PONG"
c.WriteMessage(reply)
_ = c.WriteMessage(reply)
}

func handlePong(c *Client, m *Message) {
Expand Down Expand Up @@ -116,7 +116,7 @@ func handleCap(c *Client, m *Message) {
}
}

c.Write("CAP END")
_ = c.Write("CAP END")
}
}

Expand Down
11 changes: 7 additions & 4 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@ func TestConn(t *testing.T) {

// Test writing a message
m := &Message{Prefix: &Prefix{}, Command: "PING", Params: []string{"Hello World"}}
c.WriteMessage(m)
err := c.WriteMessage(m)
assert.NoError(t, err)
testLines(t, rwc, []string{
"PING :Hello World",
})

// Test with Writef
c.Writef("PING :%s", "Hello World")
err = c.Writef("PING :%s", "Hello World")
assert.NoError(t, err)
testLines(t, rwc, []string{
"PING :Hello World",
})
Expand All @@ -124,7 +126,7 @@ func TestConn(t *testing.T) {
assert.EqualValues(t, m, m2, "Message returned by client did not match input")

rwc.server.WriteString(":invalid_message\r\n")
_, err := c.ReadMessage()
_, err = c.ReadMessage()
assert.Equal(t, ErrMissingDataAfterPrefix, err)

// Ensure empty messages are ignored
Expand Down Expand Up @@ -154,7 +156,8 @@ func TestDebugCallback(t *testing.T) {
}

m := &Message{Prefix: &Prefix{}, Command: "PING", Params: []string{"Hello World"}}
c.WriteMessage(m)
err := c.WriteMessage(m)
assert.NoError(t, err)
testLines(t, rwc, []string{
"PING :Hello World",
})
Expand Down
2 changes: 1 addition & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (t Tags) String() string {

// We don't need the first byte because that's an extra ';'
// character.
buf.ReadByte()
_, _ = buf.ReadByte()

return buf.String()
}
Expand Down

0 comments on commit b93c7df

Please sign in to comment.