aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2024-12-08 10:32:29 +0800
committerRunxi Yu <me@runxiyu.org>2024-12-08 10:32:29 +0800
commit6bbe00f0c7aae6c468b1a3e12983a74a170e92b8 (patch)
tree970b43288cdbb8c05cf5df2aaaf79e94019d13af /main.go
parentRemove another unnecessary anonymous function (diff)
downloadmeseircd-6bbe00f0c7aae6c468b1a3e12983a74a170e92b8.tar.gz
meseircd-6bbe00f0c7aae6c468b1a3e12983a74a170e92b8.tar.zst
meseircd-6bbe00f0c7aae6c468b1a3e12983a74a170e92b8.zip
Handle send failures
Diffstat (limited to 'main.go')
-rw-r--r--main.go34
1 files changed, 25 insertions, 9 deletions
diff --git a/main.go b/main.go
index 96b9b02..bd96e5d 100644
--- a/main.go
+++ b/main.go
@@ -65,28 +65,44 @@ messageLoop:
case ErrEmptyMessage:
continue messageLoop
case ErrIllegalByte:
- client.Send(MakeMsg(self, "ERROR", err.Error()))
- break messageLoop
+ err := client.Send(MakeMsg(self, "ERROR", err.Error()))
+ if err != nil {
+ slog.Error("error while reporting illegal byte", "error", err, "client", client)
+ return
+ }
+ return
case ErrTagsTooLong:
fallthrough
case ErrBodyTooLong:
- client.Send(MakeMsg(self, ERR_INPUTTOOLONG, err.Error()))
+ err := client.Send(MakeMsg(self, ERR_INPUTTOOLONG, err.Error()))
+ if err != nil {
+ slog.Error("error while reporting body too long", "error", err, "client", client)
+ return
+ }
continue messageLoop
default:
- client.Send(MakeMsg(self, "ERROR", err.Error()))
- break messageLoop
+ err := client.Send(MakeMsg(self, "ERROR", err.Error()))
+ if err != nil {
+ slog.Error("error while reporting parser error", "error", err, "client", client)
+ }
+ return
}
}
handler, ok := commandHandlers[msg.Command]
if !ok {
- client.Send(MakeMsg(self, ERR_UNKNOWNCOMMAND, msg.Command, "Unknown command"))
+ err := client.Send(MakeMsg(self, ERR_UNKNOWNCOMMAND, msg.Command, "Unknown command"))
+ if err != nil {
+ slog.Error("error while reporting unknown command", "error", err, "client", client)
+ return
+ }
continue
}
- cont := handler(msg, client)
- if !cont {
- break
+ err = handler(msg, client)
+ if err != nil {
+ slog.Error("handler error", "error", err, "client", client)
+ return
}
}
}