diff options
author | Runxi Yu <me@runxiyu.org> | 2024-12-08 10:32:29 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2024-12-08 10:32:29 +0800 |
commit | 6bbe00f0c7aae6c468b1a3e12983a74a170e92b8 (patch) | |
tree | 970b43288cdbb8c05cf5df2aaaf79e94019d13af /main.go | |
parent | Remove another unnecessary anonymous function (diff) | |
download | meseircd-6bbe00f0c7aae6c468b1a3e12983a74a170e92b8.tar.gz meseircd-6bbe00f0c7aae6c468b1a3e12983a74a170e92b8.tar.zst meseircd-6bbe00f0c7aae6c468b1a3e12983a74a170e92b8.zip |
Handle send failures
Diffstat (limited to '')
-rw-r--r-- | main.go | 34 |
1 files changed, 25 insertions, 9 deletions
@@ -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 } } } |