diff options
author | Duco van Amstel <duco.vanamstel@gmail.com> | 2018-12-08 16:04:10 +0000 |
---|---|---|
committer | Wim <wim@42.be> | 2018-12-08 17:04:10 +0100 |
commit | a2754f15fc2bc2eede94e2e41712f9f0585f2426 (patch) | |
tree | 52894a30d0ca7a06b90a7b2266fde41a5e8404c5 | |
parent | b6d81f34ba7ee88e7a18a27cf4e0aeebaaf82c79 (diff) | |
download | matterbridge-msglm-a2754f15fc2bc2eede94e2e41712f9f0585f2426.tar.gz matterbridge-msglm-a2754f15fc2bc2eede94e2e41712f9f0585f2426.tar.bz2 matterbridge-msglm-a2754f15fc2bc2eede94e2e41712f9f0585f2426.zip |
Enable errcheck linter (#646)
-rw-r--r-- | .golangci.yaml | 1 | ||||
-rw-r--r-- | bridge/slack/slack.go | 20 | ||||
-rw-r--r-- | bridge/sshchat/sshchat.go | 19 | ||||
-rw-r--r-- | matterbridge.go | 7 | ||||
-rw-r--r-- | matterclient/helpers.go | 3 | ||||
-rw-r--r-- | matterclient/matterclient.go | 4 | ||||
-rw-r--r-- | matterclient/messages.go | 8 |
7 files changed, 37 insertions, 25 deletions
diff --git a/.golangci.yaml b/.golangci.yaml index ac3f34b8..e2c82bed 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -175,7 +175,6 @@ linters-settings: linters: enable-all: true disable: - - errcheck - gochecknoglobals - gocyclo - lll diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index f9b4dd75..225e16e9 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -195,16 +195,16 @@ func (b *Bslack) Send(msg config.Message) (string, error) { // Use webhook to send the message if b.GetString(outgoingWebhookConfig) != "" { - return b.sendWebhook(msg) + return "", b.sendWebhook(msg) } return b.sendRTM(msg) } // sendWebhook uses the configured WebhookURL to send the message -func (b *Bslack) sendWebhook(msg config.Message) (string, error) { +func (b *Bslack) sendWebhook(msg config.Message) error { // Skip events. if msg.Event != "" { - return "", nil + return nil } if b.GetBool(useNickPrefixConfig) { @@ -259,9 +259,9 @@ func (b *Bslack) sendWebhook(msg config.Message) (string, error) { } if err := b.mh.Send(matterMessage); err != nil { b.Log.Errorf("Failed to send message via webhook: %#v", err) - return "", err + return err } - return "", nil + return nil } func (b *Bslack) sendRTM(msg config.Message) (string, error) { @@ -317,7 +317,7 @@ func (b *Bslack) sendRTM(msg config.Message) (string, error) { return b.postMessage(&msg, channelInfo) } -func (b *Bslack) updateTopicOrPurpose(msg *config.Message, channelInfo *slack.Channel) (bool, error) { +func (b *Bslack) updateTopicOrPurpose(msg *config.Message, channelInfo *slack.Channel) error { var updateFunc func(channelID string, value string) (*slack.Channel, error) incomingChangeType, text := b.extractTopicOrPurpose(msg.Text) @@ -328,15 +328,15 @@ func (b *Bslack) updateTopicOrPurpose(msg *config.Message, channelInfo *slack.Ch updateFunc = b.rtm.SetPurposeOfConversation default: b.Log.Errorf("Unhandled type received from extractTopicOrPurpose: %s", incomingChangeType) - return true, nil + return nil } for { _, err := updateFunc(channelInfo.ID, text) if err == nil { - return true, nil + return nil } if err = b.handleRateLimit(err); err != nil { - return true, err + return err } } } @@ -348,7 +348,7 @@ func (b *Bslack) handleTopicOrPurpose(msg *config.Message, channelInfo *slack.Ch } if b.GetBool("SyncTopic") { - return b.updateTopicOrPurpose(msg, channelInfo) + return true, b.updateTopicOrPurpose(msg, channelInfo) } // Pass along to normal message handlers. diff --git a/bridge/sshchat/sshchat.go b/bridge/sshchat/sshchat.go index 827c81de..555759bf 100644 --- a/bridge/sshchat/sshchat.go +++ b/bridge/sshchat/sshchat.go @@ -30,9 +30,10 @@ func (b *Bsshchat) Connect() error { b.r = bufio.NewScanner(r) b.w = w b.r.Scan() - w.Write([]byte("/theme mono\r\n")) - b.handleSSHChat() - return nil + if _, handleErr := w.Write([]byte("/theme mono\r\n")); handleErr != nil { + return handleErr + } + return b.handleSSHChat() }) }() if err != nil { @@ -59,7 +60,9 @@ func (b *Bsshchat) Send(msg config.Message) (string, error) { b.Log.Debugf("=> Receiving %#v", msg) if msg.Extra != nil { for _, rmsg := range helper.HandleExtra(&msg, b.General) { - b.w.Write([]byte(rmsg.Username + rmsg.Text + "\r\n")) + if _, err := b.w.Write([]byte(rmsg.Username + rmsg.Text + "\r\n")); err != nil { + b.Log.Errorf("Could not send extra message: %#v", err) + } } if len(msg.Extra["file"]) > 0 { for _, f := range msg.Extra["file"] { @@ -73,13 +76,15 @@ func (b *Bsshchat) Send(msg config.Message) (string, error) { msg.Text = fi.Comment + ": " + fi.URL } } - b.w.Write([]byte(msg.Username + msg.Text)) + if _, err := b.w.Write([]byte(msg.Username + msg.Text)); err != nil { + b.Log.Errorf("Could not send file message: %#v", err) + } } return "", nil } } - b.w.Write([]byte(msg.Username + msg.Text + "\r\n")) - return "", nil + _, err := b.w.Write([]byte(msg.Username + msg.Text + "\r\n")) + return "", err } /* diff --git a/matterbridge.go b/matterbridge.go index de63c905..e713fb0b 100644 --- a/matterbridge.go +++ b/matterbridge.go @@ -28,8 +28,11 @@ func main() { flagGops := flag.Bool("gops", false, "enable gops agent") flag.Parse() if *flagGops { - agent.Listen(agent.Options{}) - defer agent.Close() + if err := agent.Listen(agent.Options{}); err != nil { + flog.Errorf("failed to start gops agent: %#v", err) + } else { + defer agent.Close() + } } if *flagVersion { fmt.Printf("version: %s %s\n", version, githash) diff --git a/matterclient/helpers.go b/matterclient/helpers.go index 05497311..625fffaa 100644 --- a/matterclient/helpers.go +++ b/matterclient/helpers.go @@ -263,8 +263,7 @@ func (m *MMClient) sendWSRequest(action string, data map[string]interface{}) err req.Data = data m.WsSequence++ m.log.Debugf("sendWsRequest %#v", req) - m.WsClient.WriteJSON(req) - return nil + return m.WsClient.WriteJSON(req) } func supportedVersion(version string) bool { diff --git a/matterclient/matterclient.go b/matterclient/matterclient.go index 4997011b..f15b1d1b 100644 --- a/matterclient/matterclient.go +++ b/matterclient/matterclient.go @@ -208,7 +208,9 @@ func (m *MMClient) StatusLoop() { return } if m.WsConnected { - m.checkAlive() + if err := m.checkAlive(); err != nil { + log.Errorf("Connection is not alive: %#v", err) + } select { case <-m.WsPingChan: m.log.Debug("WS PONG received") diff --git a/matterclient/messages.go b/matterclient/messages.go index 28e3ec28..985cfe04 100644 --- a/matterclient/messages.go +++ b/matterclient/messages.go @@ -53,7 +53,9 @@ func (m *MMClient) parseMessage(rmsg *Message) { m.UpdateUser(user["id"].(string)) } case "group_added": - m.UpdateChannels() + if err := m.UpdateChannels(); err != nil { + m.log.Errorf("failed to update channels: %#v", err) + } /* case model.ACTION_USER_REMOVED: m.handleWsActionUserRemoved(&rmsg) @@ -186,7 +188,9 @@ func (m *MMClient) SendDirectMessageProps(toUserId string, msg string, props map channelName := model.GetDMNameFromIds(toUserId, m.User.Id) // update our channels - m.UpdateChannels() + if err := m.UpdateChannels(); err != nil { + m.log.Errorf("failed to update channels: %#v", err) + } // build & send the message msg = strings.Replace(msg, "\r", "", -1) |