Skip to content

Commit

Permalink
handle errors in hooks and pipeline execution
Browse files Browse the repository at this point in the history
- Updated `ExecuteOnDone` in `Hook` and `Step` interfaces to return an `OnFailType` and an error.
- Modified `Hooks.Execute` and `Pipeline.Execute` to handle the returned `OnFailType` and error appropriately.  This improves error handling and allows for more granular control over failure scenarios.
  • Loading branch information
flarco committed Jan 31, 2025
1 parent a68e293 commit cd3b6a8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions core/sling/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "github.com/flarco/g"

type HookType string
type HookKind string
type OnFailType string

const (
HookKindHook HookKind = "hook"
Expand All @@ -19,7 +20,7 @@ type Hook interface {
SetExtra(map[string]any)
Stage() HookStage
Execute() error
ExecuteOnDone(error) error
ExecuteOnDone(error) (OnFailType, error)
}

type Hooks []Hook
Expand Down Expand Up @@ -56,7 +57,7 @@ func (hs Hooks) Execute() (err error) {
}

hookErr := hook.Execute()
err = hook.ExecuteOnDone(hookErr)
_, err = hook.ExecuteOnDone(hookErr)

if err != nil {
return g.Error(err, "error executing hook")
Expand Down
2 changes: 1 addition & 1 deletion core/sling/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (pl *Pipeline) Execute() (err error) {
}

stepErr := step.Execute()
err = step.ExecuteOnDone(stepErr)
_, err = step.ExecuteOnDone(stepErr)

if err != nil {
return g.Error(err, "error executing step")
Expand Down

0 comments on commit cd3b6a8

Please sign in to comment.