From 7ca9755eb15e19fc619852e50ba6f60562781ffa Mon Sep 17 00:00:00 2001 From: fclairamb Date: Mon, 4 Mar 2024 00:07:02 +0100 Subject: [PATCH] More linting code improvements --- client_handler.go | 18 +++++++++--------- server_test.go | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/client_handler.go b/client_handler.go index 17145336..7020b877 100644 --- a/client_handler.go +++ b/client_handler.go @@ -463,12 +463,12 @@ func (c *clientHandler) readCommand() bool { func (c *clientHandler) handleCommandsStreamError(err error) { // florent(2018-01-14): #58: IDLE timeout: Adding some code to deal with the deadline - switch err := err.(type) { - case net.Error: - if err.Timeout() { + var errNetError net.Error + if errors.As(err, &errNetError) { + if errNetError.Timeout() { // We have to extend the deadline now - if err := c.conn.SetDeadline(time.Now().Add(time.Minute)); err != nil { - c.logger.Error("Could not set read deadline", "err", err) + if errSet := c.conn.SetDeadline(time.Now().Add(time.Minute)); errSet != nil { + c.logger.Error("Could not set read deadline", "err", errSet) } c.logger.Info("Client IDLE timeout", "err", err) @@ -476,15 +476,15 @@ func (c *clientHandler) handleCommandsStreamError(err error) { StatusServiceNotAvailable, fmt.Sprintf("command timeout (%d seconds): closing control connection", c.server.settings.IdleTimeout)) - if err := c.writer.Flush(); err != nil { - c.logger.Error("Flush error", "err", err) + if errFlush := c.writer.Flush(); errFlush != nil { + c.logger.Error("Flush error", "err", errFlush) } - break + return } c.logger.Error("Network error", "err", err) - default: + } else { if errors.Is(err, io.EOF) { if c.debug { c.logger.Debug("Client disconnected", "clean", false) diff --git a/server_test.go b/server_test.go index a78027d9..33fc5cf8 100644 --- a/server_test.go +++ b/server_test.go @@ -195,7 +195,7 @@ func TestServerSettingsIPError(t *testing.T) { } err := server.loadSettings() - _, ok := err.(*ipValidationError) + _, ok := err.(*ipValidationError) //nolint:errorlint // Here we want to test the exact error match require.True(t, ok) }) @@ -207,7 +207,7 @@ func TestServerSettingsIPError(t *testing.T) { } err := server.loadSettings() - _, ok := err.(*ipValidationError) + _, ok := err.(*ipValidationError) //nolint:errorlint // Here we want to test the exact error match require.True(t, ok) })