From 8c539370aa846c92fcfe1ca2fc7da790e3c94135 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 16 Mar 2020 12:53:48 +0100 Subject: [PATCH] remove cerr --- api/request.param.go | 14 ++++++--- internal/cerr/cerr.go | 36 ----------------------- internal/cerr/cerr_test.go | 57 ------------------------------------- internal/multipart/types.go | 14 ++++++--- 4 files changed, 20 insertions(+), 101 deletions(-) delete mode 100644 internal/cerr/cerr.go delete mode 100644 internal/cerr/cerr_test.go diff --git a/api/request.param.go b/api/request.param.go index ae1073c..10b53b4 100644 --- a/api/request.param.go +++ b/api/request.param.go @@ -2,15 +2,21 @@ package api import ( "fmt" - - "git.xdrm.io/go/aicra/internal/cerr" ) +// Error allows you to create constant "const" error with type boxing. +type Error string + +// Error implements the error builtin interface. +func (err Error) Error() string { + return string(err) +} + // ErrReqParamNotFound is thrown when a request parameter is not found -const ErrReqParamNotFound = cerr.Error("request parameter not found") +const ErrReqParamNotFound = Error("request parameter not found") // ErrReqParamNotType is thrown when a request parameter is not asked with the right type -const ErrReqParamNotType = cerr.Error("request parameter does not fulfills type") +const ErrReqParamNotType = Error("request parameter does not fulfills type") // RequestParam defines input parameters of an api request type RequestParam map[string]interface{} diff --git a/internal/cerr/cerr.go b/internal/cerr/cerr.go deleted file mode 100644 index 19a8e6d..0000000 --- a/internal/cerr/cerr.go +++ /dev/null @@ -1,36 +0,0 @@ -package cerr - -// Error allows you to create constant "const" error with type boxing. -type Error string - -// Error implements the error builtin interface. -func (err Error) Error() string { - return string(err) -} - -// Wrap returns a new error which wraps a new error into itself. -func (err Error) Wrap(e error) *WrapError { - return &WrapError{ - base: err, - wrap: e, - } -} - -// WrapString returns a new error which wraps a new error created from a string. -func (err Error) WrapString(e string) *WrapError { - return &WrapError{ - base: err, - wrap: Error(e), - } -} - -// WrapError is way to wrap errors recursively. -type WrapError struct { - base error - wrap error -} - -// Error implements the error builtin interface recursively. -func (err *WrapError) Error() string { - return err.base.Error() + ": " + err.wrap.Error() -} diff --git a/internal/cerr/cerr_test.go b/internal/cerr/cerr_test.go deleted file mode 100644 index 476996c..0000000 --- a/internal/cerr/cerr_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package cerr - -import ( - "errors" - "fmt" - "testing" -) - -func TestConstError(t *testing.T) { - const cerr1 = Error("some-string") - const cerr2 = Error("some-other-string") - const cerr3 = Error("some-string") // same const value as @cerr1 - - if cerr1.Error() == cerr2.Error() { - t.Errorf("cerr1 should not be equal to cerr2 ('%s', '%s')", cerr1.Error(), cerr2.Error()) - } - if cerr2.Error() == cerr3.Error() { - t.Errorf("cerr2 should not be equal to cerr3 ('%s', '%s')", cerr2.Error(), cerr3.Error()) - } - if cerr1.Error() != cerr3.Error() { - t.Errorf("cerr1 should be equal to cerr3 ('%s', '%s')", cerr1.Error(), cerr3.Error()) - } -} - -func TestWrappedConstError(t *testing.T) { - const parent = Error("file error") - - const readErrorConst = Error("cannot read file") - var wrappedReadError = parent.Wrap(readErrorConst) - - expectedWrappedReadError := fmt.Sprintf("%s: %s", parent.Error(), readErrorConst.Error()) - if wrappedReadError.Error() != expectedWrappedReadError { - t.Errorf("expected '%s' (got '%s')", wrappedReadError.Error(), expectedWrappedReadError) - } -} -func TestWrappedStandardError(t *testing.T) { - const parent = Error("file error") - - var writeErrorStandard error = errors.New("cannot write file") - var wrappedWriteError = parent.Wrap(writeErrorStandard) - - expectedWrappedWriteError := fmt.Sprintf("%s: %s", parent.Error(), writeErrorStandard.Error()) - if wrappedWriteError.Error() != expectedWrappedWriteError { - t.Errorf("expected '%s' (got '%s')", wrappedWriteError.Error(), expectedWrappedWriteError) - } -} -func TestWrappedStringError(t *testing.T) { - const parent = Error("file error") - - var closeErrorString string = "cannot close file" - var wrappedCloseError = parent.WrapString(closeErrorString) - - expectedWrappedCloseError := fmt.Sprintf("%s: %s", parent.Error(), closeErrorString) - if wrappedCloseError.Error() != expectedWrappedCloseError { - t.Errorf("expected '%s' (got '%s')", wrappedCloseError.Error(), expectedWrappedCloseError) - } -} diff --git a/internal/multipart/types.go b/internal/multipart/types.go index 86fda25..83c46f8 100644 --- a/internal/multipart/types.go +++ b/internal/multipart/types.go @@ -1,15 +1,21 @@ package multipart -import "git.xdrm.io/go/aicra/internal/cerr" +// Error allows you to create constant "const" error with type boxing. +type Error string + +// Error implements the error builtin interface. +func (err Error) Error() string { + return string(err) +} // ErrMissingDataName is set when a multipart variable/file has no name="..." -const ErrMissingDataName = cerr.Error("data has no name") +const ErrMissingDataName = Error("data has no name") // ErrDataNameConflict is set when a multipart variable/file name is already used -const ErrDataNameConflict = cerr.Error("data name conflict") +const ErrDataNameConflict = Error("data name conflict") // ErrNoHeader is set when a multipart variable/file has no (valid) header -const ErrNoHeader = cerr.Error("data has no header") +const ErrNoHeader = Error("data has no header") // Component represents a multipart variable/file type Component struct {