mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-25 09:48:32 +02:00
feat(idlesleep): support container dependencies, including custom and docker depends_on, code refactor
This commit is contained in:
65
internal/idlewatcher/errors.go
Normal file
65
internal/idlewatcher/errors.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package idlewatcher
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type watcherError struct {
|
||||
watcher *Watcher
|
||||
err error
|
||||
}
|
||||
|
||||
func (e *watcherError) Unwrap() error {
|
||||
return e.err
|
||||
}
|
||||
|
||||
func (e *watcherError) Error() string {
|
||||
return fmt.Sprintf("watcher %q error: %s", e.watcher.cfg.ContainerName(), e.err.Error())
|
||||
}
|
||||
|
||||
func (w *Watcher) newWatcherError(err error) error {
|
||||
if errors.Is(err, causeReload) {
|
||||
return nil
|
||||
}
|
||||
if wErr, ok := err.(*watcherError); ok { //nolint:errorlint
|
||||
return wErr
|
||||
}
|
||||
return &watcherError{watcher: w, err: convertError(err)}
|
||||
}
|
||||
|
||||
type depError struct {
|
||||
action string
|
||||
dep *dependency
|
||||
err error
|
||||
}
|
||||
|
||||
func (e *depError) Unwrap() error {
|
||||
return e.err
|
||||
}
|
||||
|
||||
func (e *depError) Error() string {
|
||||
return fmt.Sprintf("%s failed for dependency %q: %s", e.action, e.dep.cfg.ContainerName(), e.err.Error())
|
||||
}
|
||||
|
||||
func (w *Watcher) newDepError(action string, dep *dependency, err error) error {
|
||||
if errors.Is(err, causeReload) {
|
||||
return nil
|
||||
}
|
||||
if dErr, ok := err.(*depError); ok { //nolint:errorlint
|
||||
return dErr
|
||||
}
|
||||
return w.newWatcherError(&depError{action: action, dep: dep, err: convertError(err)})
|
||||
}
|
||||
|
||||
func convertError(err error) error {
|
||||
switch {
|
||||
case err == nil:
|
||||
return nil
|
||||
case errors.Is(err, context.DeadlineExceeded):
|
||||
return errors.New("timeout")
|
||||
default:
|
||||
return err
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user