From db0e4ba8c5d290160411e7be889609bb41bef174 Mon Sep 17 00:00:00 2001 From: Wim Date: Sat, 8 Oct 2016 21:57:03 +0200 Subject: [PATCH] Add error message about non-existing channels (slack) --- bridge/slack/slack.go | 15 ++++++++++----- gateway/gateway.go | 6 +++++- gateway/samechannel/samechannel.go | 5 ++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index d0156ec8..62cb04b7 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -1,6 +1,7 @@ package bslack import ( + "fmt" "github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/matterhook" log "github.com/Sirupsen/logrus" @@ -115,21 +116,25 @@ func (b *Bslack) SendType(nick string, message string, channel string, mtype str } return nil } - newmsg := b.rtm.NewOutgoingMessage(message, b.getChannelByName(channel).ID) + schannel, err := b.getChannelByName(channel) + if err != nil { + return err + } + newmsg := b.rtm.NewOutgoingMessage(message, schannel.ID) b.rtm.SendMessage(newmsg) return nil } -func (b *Bslack) getChannelByName(name string) *slack.Channel { +func (b *Bslack) getChannelByName(name string) (*slack.Channel, error) { if b.channels == nil { - return nil + return nil, fmt.Errorf("%s: channel %s not found (no channels found)", b.FullOrigin(), name) } for _, channel := range b.channels { if channel.Name == name { - return &channel + return &channel, nil } } - return nil + return nil, fmt.Errorf("%s: channel %s not found", b.FullOrigin(), name) } func (b *Bslack) handleSlack() { diff --git a/gateway/gateway.go b/gateway/gateway.go index fefbaeb2..6f797997 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -1,6 +1,7 @@ package gateway import ( + "fmt" "github.com/42wim/matterbridge/bridge" "github.com/42wim/matterbridge/bridge/config" log "github.com/Sirupsen/logrus" @@ -109,7 +110,10 @@ func (gw *Gateway) handleMessage(msg config.Message, dest bridge.Bridge) { } gw.modifyMessage(&msg, dest) log.Debugf("Sending %#v from %s to %s", msg, msg.FullOrigin, dest.FullOrigin()) - dest.Send(msg) + err := dest.Send(msg) + if err != nil { + fmt.Println(err) + } } } diff --git a/gateway/samechannel/samechannel.go b/gateway/samechannel/samechannel.go index c7b3d624..5cdd59ae 100644 --- a/gateway/samechannel/samechannel.go +++ b/gateway/samechannel/samechannel.go @@ -60,7 +60,10 @@ func (gw *SameChannelGateway) handleMessage(msg config.Message, dest bridge.Brid } gw.modifyMessage(&msg, dest) log.Debugf("Sending %#v from %s to %s", msg, msg.FullOrigin, dest.FullOrigin()) - dest.Send(msg) + err := dest.Send(msg) + if err != nil { + log.Error(err) + } } func setNickFormat(msg *config.Message, format string) {