Skip to content

Commit c9c1303

Browse files
authored
Merge pull request #1777 from ktock/fixerrormsg
monitor: improve error messages
2 parents ae3299d + 437fe55 commit c9c1303

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

monitor/commands/attach.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (cm *AttachCmd) Info() types.CommandInfo {
2525

2626
func (cm *AttachCmd) Exec(ctx context.Context, args []string) error {
2727
if len(args) < 2 {
28-
return errors.Errorf("server name must be passed")
28+
return errors.Errorf("ID of session or process must be passed")
2929
}
3030
ref := args[1]
3131
var id string
@@ -58,7 +58,11 @@ func (cm *AttachCmd) Exec(ctx context.Context, args []string) error {
5858
}
5959

6060
func isProcessID(ctx context.Context, c types.Monitor, ref string) (bool, error) {
61-
infos, err := c.ListProcesses(ctx, c.AttachedSessionID())
61+
sid := c.AttachedSessionID()
62+
if sid == "" {
63+
return false, errors.Errorf("no attaching session")
64+
}
65+
infos, err := c.ListProcesses(ctx, sid)
6266
if err != nil {
6367
return false, err
6468
}

monitor/commands/disconnect.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ func (cm *DisconnectCmd) Exec(ctx context.Context, args []string) error {
2323
target := cm.m.AttachedSessionID()
2424
if len(args) >= 2 {
2525
target = args[1]
26+
} else if target == "" {
27+
return errors.Errorf("no attaching session")
2628
}
2729
isProcess, err := isProcessID(ctx, cm.m, target)
2830
if err == nil && isProcess {
29-
if err := cm.m.DisconnectProcess(ctx, cm.m.AttachedSessionID(), target); err != nil {
31+
sid := cm.m.AttachedSessionID()
32+
if sid == "" {
33+
return errors.Errorf("no attaching session")
34+
}
35+
if err := cm.m.DisconnectProcess(ctx, sid, target); err != nil {
3036
return errors.Errorf("disconnecting from process failed %v", target)
3137
}
3238
return nil

monitor/commands/ps.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"text/tabwriter"
88

99
"github.com/docker/buildx/monitor/types"
10+
"github.com/pkg/errors"
1011
)
1112

1213
type PsCmd struct {
@@ -24,6 +25,9 @@ func (cm *PsCmd) Info() types.CommandInfo {
2425

2526
func (cm *PsCmd) Exec(ctx context.Context, args []string) error {
2627
ref := cm.m.AttachedSessionID()
28+
if ref == "" {
29+
return errors.Errorf("no attaching session")
30+
}
2731
plist, err := cm.m.ListProcesses(ctx, ref)
2832
if err != nil {
2933
return err

0 commit comments

Comments
 (0)