add a default statut messsage to exec error to avoid empty line display

Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
Guillaume Lours 2025-06-27 16:11:49 +02:00 committed by Nicolas De loof
parent 257ea7b75d
commit 3553aa26a6
2 changed files with 4 additions and 3 deletions

View File

@ -18,6 +18,7 @@ package compose
import (
"context"
"fmt"
"github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli"
@ -109,8 +110,8 @@ func runExec(ctx context.Context, dockerCli command.Cli, backend api.Service, op
exitCode, err := backend.Exec(ctx, projectName, execOpts)
if exitCode != 0 {
errMsg := ""
if err != nil {
errMsg := fmt.Sprintf("exit status %d", exitCode)
if err != nil && err.Error() != "" {
errMsg = err.Error()
}
return cli.StatusError{StatusCode: exitCode, Status: errMsg}

View File

@ -52,7 +52,7 @@ func (s *composeService) Exec(ctx context.Context, projectName string, options a
err = container.RunExec(ctx, s.dockerCli, target.ID, exec)
var sterr cli.StatusError
if errors.As(err, &sterr) {
return sterr.StatusCode, nil
return sterr.StatusCode, err
}
return 0, err
}