remove cerr
This commit is contained in:
parent
acd0e73438
commit
8c539370aa
|
@ -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{}
|
||||
|
|
|
@ -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()
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue