From e00ab757bfa04bf644f04d771ea824ffad6cfad4 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Sat, 25 Apr 2026 14:31:43 -0500 Subject: [PATCH] fix(ux): include lifecycle phase name in hook error messages initializeCommand errors now include "initializeCommand" and the command name. Lifecycle hook errors (postCreateCommand, etc.) now include the phase name so users can identify which phase failed. --- pkg/devcontainer/run.go | 5 ++++- pkg/devcontainer/setup/lifecyclehooks.go | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/devcontainer/run.go b/pkg/devcontainer/run.go index e3307607d..e75dda2c4 100644 --- a/pkg/devcontainer/run.go +++ b/pkg/devcontainer/run.go @@ -305,7 +305,10 @@ func (c *initCmdContext) runSingle(name string, cmd []string) error { c2.Stderr = errwriter c2.Dir = c.workspaceFolder c2.Env = env - return c2.Run() + if err := c2.Run(); err != nil { + return fmt.Errorf("initializeCommand %q failed: %w", name, err) + } + return nil } func getWorkspace( diff --git a/pkg/devcontainer/setup/lifecyclehooks.go b/pkg/devcontainer/setup/lifecyclehooks.go index 2aadfaaa7..7338cb98c 100644 --- a/pkg/devcontainer/setup/lifecyclehooks.go +++ b/pkg/devcontainer/setup/lifecyclehooks.go @@ -488,10 +488,10 @@ func runSingleHookCommand( Env: append(os.Environ(), remoteEnvArr...), } - return executeAndLog(cmd, key, c) + return executeAndLog(cmd, p.name, key, c) } -func executeAndLog(cmd *exec.Cmd, key string, c []string) error { +func executeAndLog(cmd *exec.Cmd, phaseName string, key string, c []string) error { stdoutPipe, err := cmd.StdoutPipe() if err != nil { return fmt.Errorf("failed to get stdout pipe: %w", err) @@ -526,7 +526,7 @@ func executeAndLog(cmd *exec.Cmd, key string, c []string) error { cmd.Args, err, ) - return fmt.Errorf("failed to run: %s, error: %w", strings.Join(c, " "), err) + return fmt.Errorf("%s: command %q failed: %w", phaseName, strings.Join(c, " "), err) } log.Infof("ran command: command=%s, args=%s", key, strings.Join(c, " "))