60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package errors
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"path/filepath"
|
|
)
|
|
|
|
var (
|
|
ErrCacheUninitialized = errors.New("the route cache is uninitialized")
|
|
ErrFailedToCreateRouteCache = errors.New("failed to create route cache")
|
|
ErrRouterNotCreated = errors.New("router not created")
|
|
)
|
|
|
|
type ErrRouteNotFound struct {
|
|
route string
|
|
}
|
|
|
|
func NewErrRouteNotFound(route string) error {
|
|
return &ErrRouteNotFound{route: route}
|
|
}
|
|
|
|
func (e ErrRouteNotFound) Error() string {
|
|
return "route not found: " + string(e.route)
|
|
}
|
|
|
|
type ErrBadgerInit struct {
|
|
baseDir string
|
|
subDir string
|
|
}
|
|
|
|
func NewErrBadgerInit(baseDir, subDir string) error {
|
|
return &ErrBadgerInit{baseDir: baseDir, subDir: subDir}
|
|
}
|
|
|
|
func (e ErrBadgerInit) Error() string {
|
|
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 directory: %s", filepath.Join(e.baseDir, e.subDir))
|
|
}
|
|
|
|
type WrappedErr struct {
|
|
e error
|
|
with error
|
|
}
|
|
|
|
func Wrap(e, with error) WrappedErr {
|
|
return WrappedErr{e: e, with: with}
|
|
}
|
|
|
|
func (e WrappedErr) Error() string {
|
|
return fmt.Sprintf(`%s: %s`, e.e, e.with)
|
|
}
|
|
|
|
func (e WrappedErr) Unwrap() error {
|
|
return e.e
|
|
}
|