joist/internal/errors/errors.go

52 lines
1.0 KiB
Go

package errors
import (
"errors"
"fmt"
"path/filepath"
)
var ErrCacheUninitialized = errors.New("the route cache is uninitialized")
type ErrRouteNotFound struct {
n string
}
func (e ErrRouteNotFound) Error() string {
return "route not found: " + string(e.n)
}
func NewErrRouteNotFound(n string) error {
return &ErrRouteNotFound{n: n}
}
type ErrBadgerInit struct {
baseDir string
subDir string
}
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))
}
func NewErrBadgerInit(baseDir, subDir string) error {
return &ErrBadgerInit{baseDir: baseDir, subDir: subDir}
}
type ContextAwareErr struct {
base error
current error
}
func NewContextAwareErr(base, e error) ContextAwareErr {
return ContextAwareErr{base: base, current: e}
}
func (e ContextAwareErr) Error() string {
return fmt.Sprintf(`%s: %s`, e.base, e.current)
}