Routing Support #4

Merged
cerbervs merged 5 commits from feat/routing into main 2025-09-06 21:58:04 +00:00
2 changed files with 20 additions and 16 deletions
Showing only changes of commit 4c6e0c9ffb - Show all commits

View File

@ -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
} }

View File

@ -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{