Use eris for error management

This commit is contained in:
Jamie Curnow
2023-02-24 17:19:07 +10:00
parent 80315bd50e
commit c288886fd4
44 changed files with 173 additions and 128 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/fatih/color"
"github.com/getsentry/sentry-go"
"github.com/rotisserie/eris"
)
var colorReset, colorGray, colorYellow, colorBlue, colorRed, colorMagenta, colorBlack, colorWhite *color.Color
@ -98,7 +99,7 @@ func (l *Logger) Configure(c *Config) error {
defer l.mux.Unlock()
if c == nil {
return fmt.Errorf("a non nil Config is mandatory")
return eris.Errorf("a non nil Config is mandatory")
}
if err := c.LogThreshold.validate(); err != nil {
@ -125,7 +126,7 @@ func (l Level) validate() error {
case DebugLevel, InfoLevel, WarnLevel, ErrorLevel:
return nil
default:
return fmt.Errorf("invalid \"Level\" %d", l)
return eris.Errorf("invalid \"Level\" %d", l)
}
}

View File

@ -2,14 +2,13 @@ package logger
import (
"bytes"
"errors"
"fmt"
"io"
"log"
"os"
"testing"
"github.com/getsentry/sentry-go"
"github.com/rotisserie/eris"
"github.com/stretchr/testify/assert"
)
@ -34,7 +33,7 @@ func TestThreshold(t *testing.T) {
Info("this should display")
assert.NotEmpty(t, buf.String())
Error("ErrorClass", errors.New("this should display"))
Error("ErrorClass", eris.New("this should display"))
assert.NotEmpty(t, buf.String())
}
@ -97,7 +96,7 @@ func TestError(t *testing.T) {
LogThreshold: ErrorLevel,
}))
Error("TestErrorClass", fmt.Errorf("this is a %s error", "test"))
Error("TestErrorClass", eris.Errorf("this is a %s error", "test"))
assert.Contains(t, buf.String(), "ERROR")
assert.Contains(t, buf.String(), "this is a test error")
}