From ded91da5758c09ed42d74155307c1079e7da746f Mon Sep 17 00:00:00 2001 From: Kohei Tokunaga Date: Fri, 13 Oct 2023 10:14:04 +0900 Subject: [PATCH] exec, rollback: return error when no session found Signed-off-by: Kohei Tokunaga --- monitor/commands/exec.go | 3 +++ monitor/commands/rollback.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/monitor/commands/exec.go b/monitor/commands/exec.go index 1b9dd4db..7a0abe28 100644 --- a/monitor/commands/exec.go +++ b/monitor/commands/exec.go @@ -35,6 +35,9 @@ COMMAND and ARG... will be executed in the container. } func (cm *ExecCmd) Exec(ctx context.Context, args []string) error { + if ref := cm.m.AttachedSessionID(); ref == "" { + return errors.Errorf("no attaching session") + } if len(args) < 2 { return errors.Errorf("command must be passed") } diff --git a/monitor/commands/rollback.go b/monitor/commands/rollback.go index 0ac986a4..d56e4161 100644 --- a/monitor/commands/rollback.go +++ b/monitor/commands/rollback.go @@ -7,6 +7,7 @@ import ( controllerapi "github.com/docker/buildx/controller/pb" "github.com/docker/buildx/monitor/types" + "github.com/pkg/errors" ) type RollbackCmd struct { @@ -37,6 +38,9 @@ COMMAND and ARG... will be executed in the container. } func (cm *RollbackCmd) Exec(ctx context.Context, args []string) error { + if ref := cm.m.AttachedSessionID(); ref == "" { + return errors.Errorf("no attaching session") + } cfg := cm.invokeConfig if len(args) >= 2 { cmds := args[1:]