Skip to content

Commit

Permalink
Refactor command package errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ksysoev committed Dec 3, 2023
1 parent 748f584 commit 3fb4826
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
73 changes: 73 additions & 0 deletions pkg/command/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package command

type ErrUnknownCommand struct {
Command string
}

func (e ErrUnknownCommand) Error() string {
return "unknown command: " + e.Command
}

type ErrConnectionClosed struct{}

func (e ErrConnectionClosed) Error() string {
return "connection closed"
}

type ErrTimeout struct{}

func (e ErrTimeout) Error() string {
return "timeout"
}

type ErrUnsupportedMessageType struct {
MsgType string
}

func (e ErrUnsupportedMessageType) Error() string {
return "unsupported message type: " + e.MsgType
}

type ErrEmptyRequest struct{}

func (e ErrEmptyRequest) Error() string {
return "empty request"
}

type ErrInvalidTimeout struct {
Timeout string
}

func (e ErrInvalidTimeout) Error() string {
return "invalid timeout: " + e.Timeout
}

type ErrEmptyCommand struct{}

func (e ErrEmptyCommand) Error() string {
return "empty command"
}

type ErrEmptyMacro struct {
MacroName string
}

func (e ErrEmptyMacro) Error() string {
return "empty macro: " + e.MacroName
}

type ErrDuplicateMacro struct {
MacroName string
}

func (e ErrDuplicateMacro) Error() string {
return "duplicate macro: " + e.MacroName
}

type ErrUnsupportedVersion struct {
Version string
}

func (e ErrUnsupportedVersion) Error() string {
return "unsupported version: " + e.Version
}
31 changes: 31 additions & 0 deletions pkg/command/errors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package command

import "testing"

func TestUnknownCommand_Error(t *testing.T) {
command := "test"
err := ErrUnknownCommand{Command: command}
expected := "unknown command: " + command

if err.Error() != expected {
t.Errorf("Expected error message '%s', but got '%s'", expected, err.Error())
}
}

func TestConnectionClosed_Error(t *testing.T) {
err := ErrConnectionClosed{}
want := "connection closed"

if got := err.Error(); got != want {
t.Errorf("Error() = %v, want %v", got, want)
}
}

func TestTimeout_Error(t *testing.T) {
err := ErrTimeout{}
want := "timeout"

if got := err.Error(); got != want {
t.Errorf("Error() = %v, want %v", got, want)
}
}

0 comments on commit 3fb4826

Please sign in to comment.