refactor(errors): rename ContextAwareErr to WrappedErr
This commit is contained in:
parent
50f3748ed2
commit
4c6e0c9ffb
@ -9,15 +9,15 @@ import (
|
|||||||
var ErrCacheUninitialized = errors.New("the route cache is uninitialized")
|
var ErrCacheUninitialized = errors.New("the route cache is uninitialized")
|
||||||
|
|
||||||
type ErrRouteNotFound struct {
|
type ErrRouteNotFound struct {
|
||||||
n string
|
route string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewErrRouteNotFound(route string) error {
|
||||||
|
return &ErrRouteNotFound{route: route}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ErrRouteNotFound) Error() string {
|
func (e ErrRouteNotFound) Error() string {
|
||||||
return "route not found: " + string(e.n)
|
return "route not found: " + string(e.route)
|
||||||
}
|
|
||||||
|
|
||||||
func NewErrRouteNotFound(n string) error {
|
|
||||||
return &ErrRouteNotFound{n: n}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ErrBadgerInit struct {
|
type ErrBadgerInit struct {
|
||||||
@ -25,6 +25,10 @@ type ErrBadgerInit struct {
|
|||||||
subDir string
|
subDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewErrBadgerInit(baseDir, subDir string) error {
|
||||||
|
return &ErrBadgerInit{baseDir: baseDir, subDir: subDir}
|
||||||
|
}
|
||||||
|
|
||||||
func (e ErrBadgerInit) Error() string {
|
func (e ErrBadgerInit) Error() string {
|
||||||
if e.subDir == "" {
|
if e.subDir == "" {
|
||||||
return fmt.Sprintf("failed to initialize badger store at base directory: %s", e.baseDir)
|
return fmt.Sprintf("failed to initialize badger store at base directory: %s", e.baseDir)
|
||||||
@ -33,19 +37,19 @@ func (e ErrBadgerInit) Error() string {
|
|||||||
return fmt.Sprintf("failed to initialize badger store at directory: %s", filepath.Join(e.baseDir, e.subDir))
|
return fmt.Sprintf("failed to initialize badger store at directory: %s", filepath.Join(e.baseDir, e.subDir))
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewErrBadgerInit(baseDir, subDir string) error {
|
type WrappedErr struct {
|
||||||
return &ErrBadgerInit{baseDir: baseDir, subDir: subDir}
|
e error
|
||||||
|
with error
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContextAwareErr struct {
|
func Wrap(e, with error) WrappedErr {
|
||||||
base error
|
return WrappedErr{e: e, with: with}
|
||||||
current error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewContextAwareErr(base, e error) ContextAwareErr {
|
func (e WrappedErr) Error() string {
|
||||||
return ContextAwareErr{base: base, current: e}
|
return fmt.Sprintf(`%s: %s`, e.e, e.with)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ContextAwareErr) Error() string {
|
func (e WrappedErr) Unwrap() error {
|
||||||
return fmt.Sprintf(`%s: %s`, e.base, e.current)
|
return e.e
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ func WithStore(store Storer) RouteCacheOpt {
|
|||||||
func NewRouteCache(opts ...RouteCacheOpt) (*routeCache, error) {
|
func NewRouteCache(opts ...RouteCacheOpt) (*routeCache, error) {
|
||||||
s, err := badger.NewBadgerStore(badger.WithSubDir("route_cache"))
|
s, err := badger.NewBadgerStore(badger.WithSubDir("route_cache"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, jerr.NewContextAwareErr(jerr.ErrCacheUninitialized, err)
|
return nil, jerr.Wrap(jerr.ErrCacheUninitialized, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c = &routeCache{
|
c = &routeCache{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user