From 752cc0af047069179841145dcddb47ac71090feb Mon Sep 17 00:00:00 2001 From: Josh Deprez Date: Mon, 29 Jul 2024 13:43:26 +1000 Subject: [PATCH] Minor error tweaks in command phase --- internal/job/executor.go | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/internal/job/executor.go b/internal/job/executor.go index a1aa5fd52c..d77f8dae08 100644 --- a/internal/job/executor.go +++ b/internal/job/executor.go @@ -831,58 +831,48 @@ func (e *Executor) tearDown(ctx context.Context) error { } // runPreCommandHooks runs the pre-command hooks and adds tracing spans. -func (e *Executor) runPreCommandHooks(ctx context.Context) error { +func (e *Executor) runPreCommandHooks(ctx context.Context) (err error) { spanName := e.implementationSpecificSpanName("pre-command", "pre-command hooks") span, ctx := tracetools.StartSpanFromContext(ctx, spanName, e.ExecutorConfig.TracingBackend) - var err error defer func() { span.FinishWithError(err) }() - if err = e.executeGlobalHook(ctx, "pre-command"); err != nil { - return err - } - if err = e.executeLocalHook(ctx, "pre-command"); err != nil { + if err := e.executeGlobalHook(ctx, "pre-command"); err != nil { return err } - if err = e.executePluginHook(ctx, "pre-command", e.pluginCheckouts); err != nil { + if err := e.executeLocalHook(ctx, "pre-command"); err != nil { return err } - return nil + return e.executePluginHook(ctx, "pre-command", e.pluginCheckouts) } // runCommand runs the command and adds tracing spans. func (e *Executor) runCommand(ctx context.Context) error { - var err error // There can only be one command hook, so we check them in order of plugin, local switch { case e.hasPluginHook("command"): - err = e.executePluginHook(ctx, "command", e.pluginCheckouts) + return e.executePluginHook(ctx, "command", e.pluginCheckouts) case e.hasLocalHook("command"): - err = e.executeLocalHook(ctx, "command") + return e.executeLocalHook(ctx, "command") case e.hasGlobalHook("command"): - err = e.executeGlobalHook(ctx, "command") + return e.executeGlobalHook(ctx, "command") default: - err = e.defaultCommandPhase(ctx) + return e.defaultCommandPhase(ctx) } - return err } // runPostCommandHooks runs the post-command hooks and adds tracing spans. -func (e *Executor) runPostCommandHooks(ctx context.Context) error { +func (e *Executor) runPostCommandHooks(ctx context.Context) (err error) { spanName := e.implementationSpecificSpanName("post-command", "post-command hooks") span, ctx := tracetools.StartSpanFromContext(ctx, spanName, e.ExecutorConfig.TracingBackend) - var err error defer func() { span.FinishWithError(err) }() - if err = e.executeGlobalHook(ctx, "post-command"); err != nil { + if err := e.executeGlobalHook(ctx, "post-command"); err != nil { return err } - if err = e.executeLocalHook(ctx, "post-command"); err != nil { + if err := e.executeLocalHook(ctx, "post-command"); err != nil { return err } - if err = e.executePluginHook(ctx, "post-command", e.pluginCheckouts); err != nil { - return err - } - return nil + return e.executePluginHook(ctx, "post-command", e.pluginCheckouts) } // CommandPhase determines how to run the build, and then runs it