From b0a0d62f7e62c73f18779247f851d486f7d1efae Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Mon, 26 Oct 2026 17:29:22 +0900 Subject: [PATCH] limactl-menu: do not leak `limactl list` warnings to the terminal `listInstances` passed the stderr of `limactl list --json` through to the terminal. On a fresh installation it printed "No instance found. Run `limactl create` to create an instance." before the TUI started. The warning stayed hidden behind the TUI and reappeared when the menu suspended to run `limactl create`, which was confusing. Buffer the stderr and only include it in the error when the command fails. Also fix the error from `cmd.Start()` being discarded. Fixes #5681 Assisted-by: Claude Opus 5.5 (1M context) Signed-off-by: Akihiro Suda --- cmd/limactl-menu/main.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/limactl-menu/main.go b/cmd/limactl-menu/main.go index e40e0ddf..71de9f21 100644 --- a/cmd/limactl-menu/main.go +++ b/cmd/limactl-menu/main.go @@ -5,6 +5,7 @@ package main import ( "bufio" + "bytes" "context" "encoding/json" "fmt" @@ -514,9 +515,16 @@ func (s *State) showEmptyState() { func listInstances(ctx context.Context, limactl string) ([]*limatype.Instance, error) { cmd := exec.CommandContext(ctx, limactl, "list", "--json") - cmd.Stderr = os.Stderr + // Buffer stderr rather than writing it to the terminal, so that warnings such as + // "No instance found. Run `limactl create` ..." do not reappear when the menu + // suspends the TUI to run another limactl command. + var stderr bytes.Buffer + cmd.Stderr = &stderr stdout, err := cmd.StdoutPipe() - if err != nil || cmd.Start() != nil { + if err != nil { + return nil, err + } + if err := cmd.Start(); err != nil { return nil, err } var res []*limatype.Instance @@ -529,7 +537,7 @@ func listInstances(ctx context.Context, limactl string) ([]*limatype.Instance, e res = append(res, &in) } if err := cmd.Wait(); err != nil { - return nil, err + return nil, fmt.Errorf("failed to run `limactl list --json`: %w: %s", err, strings.TrimSpace(stderr.String())) } slices.SortFunc(res, func(a, b *limatype.Instance) int { if (a.Status == "Running") != (b.Status == "Running") {