5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-22 15:10:28 +00:00

Enable errcheck linter (#646)

This commit is contained in:
Duco van Amstel 2018-12-08 16:04:10 +00:00 committed by Wim
parent b6d81f34ba
commit a2754f15fc
7 changed files with 37 additions and 25 deletions

View File

@ -175,7 +175,6 @@ linters-settings:
linters: linters:
enable-all: true enable-all: true
disable: disable:
- errcheck
- gochecknoglobals - gochecknoglobals
- gocyclo - gocyclo
- lll - lll

View File

@ -195,16 +195,16 @@ func (b *Bslack) Send(msg config.Message) (string, error) {
// Use webhook to send the message // Use webhook to send the message
if b.GetString(outgoingWebhookConfig) != "" { if b.GetString(outgoingWebhookConfig) != "" {
return b.sendWebhook(msg) return "", b.sendWebhook(msg)
} }
return b.sendRTM(msg) return b.sendRTM(msg)
} }
// sendWebhook uses the configured WebhookURL to send the message // 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. // Skip events.
if msg.Event != "" { if msg.Event != "" {
return "", nil return nil
} }
if b.GetBool(useNickPrefixConfig) { 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 { if err := b.mh.Send(matterMessage); err != nil {
b.Log.Errorf("Failed to send message via webhook: %#v", err) 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) { 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) 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) var updateFunc func(channelID string, value string) (*slack.Channel, error)
incomingChangeType, text := b.extractTopicOrPurpose(msg.Text) incomingChangeType, text := b.extractTopicOrPurpose(msg.Text)
@ -328,15 +328,15 @@ func (b *Bslack) updateTopicOrPurpose(msg *config.Message, channelInfo *slack.Ch
updateFunc = b.rtm.SetPurposeOfConversation updateFunc = b.rtm.SetPurposeOfConversation
default: default:
b.Log.Errorf("Unhandled type received from extractTopicOrPurpose: %s", incomingChangeType) b.Log.Errorf("Unhandled type received from extractTopicOrPurpose: %s", incomingChangeType)
return true, nil return nil
} }
for { for {
_, err := updateFunc(channelInfo.ID, text) _, err := updateFunc(channelInfo.ID, text)
if err == nil { if err == nil {
return true, nil return nil
} }
if err = b.handleRateLimit(err); err != 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") { if b.GetBool("SyncTopic") {
return b.updateTopicOrPurpose(msg, channelInfo) return true, b.updateTopicOrPurpose(msg, channelInfo)
} }
// Pass along to normal message handlers. // Pass along to normal message handlers.

View File

@ -30,9 +30,10 @@ func (b *Bsshchat) Connect() error {
b.r = bufio.NewScanner(r) b.r = bufio.NewScanner(r)
b.w = w b.w = w
b.r.Scan() b.r.Scan()
w.Write([]byte("/theme mono\r\n")) if _, handleErr := w.Write([]byte("/theme mono\r\n")); handleErr != nil {
b.handleSSHChat() return handleErr
return nil }
return b.handleSSHChat()
}) })
}() }()
if err != nil { if err != nil {
@ -59,7 +60,9 @@ func (b *Bsshchat) Send(msg config.Message) (string, error) {
b.Log.Debugf("=> Receiving %#v", msg) b.Log.Debugf("=> Receiving %#v", msg)
if msg.Extra != nil { if msg.Extra != nil {
for _, rmsg := range helper.HandleExtra(&msg, b.General) { 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 { if len(msg.Extra["file"]) > 0 {
for _, f := range msg.Extra["file"] { 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 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 return "", nil
} }
} }
b.w.Write([]byte(msg.Username + msg.Text + "\r\n")) _, err := b.w.Write([]byte(msg.Username + msg.Text + "\r\n"))
return "", nil return "", err
} }
/* /*

View File

@ -28,8 +28,11 @@ func main() {
flagGops := flag.Bool("gops", false, "enable gops agent") flagGops := flag.Bool("gops", false, "enable gops agent")
flag.Parse() flag.Parse()
if *flagGops { if *flagGops {
agent.Listen(agent.Options{}) if err := agent.Listen(agent.Options{}); err != nil {
defer agent.Close() flog.Errorf("failed to start gops agent: %#v", err)
} else {
defer agent.Close()
}
} }
if *flagVersion { if *flagVersion {
fmt.Printf("version: %s %s\n", version, githash) fmt.Printf("version: %s %s\n", version, githash)

View File

@ -263,8 +263,7 @@ func (m *MMClient) sendWSRequest(action string, data map[string]interface{}) err
req.Data = data req.Data = data
m.WsSequence++ m.WsSequence++
m.log.Debugf("sendWsRequest %#v", req) m.log.Debugf("sendWsRequest %#v", req)
m.WsClient.WriteJSON(req) return m.WsClient.WriteJSON(req)
return nil
} }
func supportedVersion(version string) bool { func supportedVersion(version string) bool {

View File

@ -208,7 +208,9 @@ func (m *MMClient) StatusLoop() {
return return
} }
if m.WsConnected { if m.WsConnected {
m.checkAlive() if err := m.checkAlive(); err != nil {
log.Errorf("Connection is not alive: %#v", err)
}
select { select {
case <-m.WsPingChan: case <-m.WsPingChan:
m.log.Debug("WS PONG received") m.log.Debug("WS PONG received")

View File

@ -53,7 +53,9 @@ func (m *MMClient) parseMessage(rmsg *Message) {
m.UpdateUser(user["id"].(string)) m.UpdateUser(user["id"].(string))
} }
case "group_added": 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: case model.ACTION_USER_REMOVED:
m.handleWsActionUserRemoved(&rmsg) m.handleWsActionUserRemoved(&rmsg)
@ -186,7 +188,9 @@ func (m *MMClient) SendDirectMessageProps(toUserId string, msg string, props map
channelName := model.GetDMNameFromIds(toUserId, m.User.Id) channelName := model.GetDMNameFromIds(toUserId, m.User.Id)
// update our channels // update our channels
m.UpdateChannels() if err := m.UpdateChannels(); err != nil {
m.log.Errorf("failed to update channels: %#v", err)
}
// build & send the message // build & send the message
msg = strings.Replace(msg, "\r", "", -1) msg = strings.Replace(msg, "\r", "", -1)