Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(cli): enhance error handling for multiple agents in SSH command#19943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
kacpersaw merged 3 commits intomainfromkacpersaw/bug-ssh-multi-agent-unintuitive
Sep 25, 2025
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletionscli/ssh.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -756,7 +756,23 @@ func findWorkspaceAndAgentByHostname(
hostname = strings.TrimSuffix(hostname, qualifiedSuffix)
}
hostname = normalizeWorkspaceInput(hostname)
ws, agent, _, err := GetWorkspaceAndAgent(ctx, inv, client, !disableAutostart, hostname)

ws, agent, otherAgents, err := GetWorkspaceAndAgent(ctx, inv, client, !disableAutostart, hostname)
if err != nil && strings.Contains(err.Error(), "multiple agents found") {
Copy link
Member

@ethanndicksonethanndicksonSep 25, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can we define the 'multiple agents found' error as a sentinel, and then useerrors.Is instead?

var errorMsg strings.Builder
_, _ = errorMsg.WriteString(fmt.Sprintf("%s\nTry running:\n", err.Error()))
for _, agent := range otherAgents {
switch {
case config.HostnameSuffix != "":
_, _ = errorMsg.WriteString(fmt.Sprintf("%s\n", cliui.Code(fmt.Sprintf("$ ssh %s.%s.%s.%s", agent.Name, ws.Name, ws.OwnerName, config.HostnameSuffix))))
case config.HostnamePrefix != "":
_, _ = errorMsg.WriteString(fmt.Sprintf("%s\n", cliui.Code(fmt.Sprintf("$ ssh %s%s.%s.%s", config.HostnamePrefix, agent.Name, ws.Name, ws.OwnerName))))
default:
_, _ = errorMsg.WriteString(fmt.Sprintf("%s\n", cliui.Code(fmt.Sprintf("$ ssh %s.%s.%s", agent.Name, ws.Name, ws.OwnerName))))
}
}
return ws, agent, xerrors.New(errorMsg.String())
}
return ws, agent, err
}

Expand DownExpand Up@@ -922,7 +938,7 @@ func GetWorkspaceAndAgent(ctx context.Context, inv *serpent.Invocation, client *
}
workspaceAgent, otherWorkspaceAgents, err := getWorkspaceAgent(workspace, agentName)
if err != nil {
returncodersdk.Workspace{}, codersdk.WorkspaceAgent{},nil, err
returnworkspace, codersdk.WorkspaceAgent{},otherWorkspaceAgents, err
}

return workspace, workspaceAgent, otherWorkspaceAgents, nil
Expand DownExpand Up@@ -958,7 +974,7 @@ func getWorkspaceAgent(workspace codersdk.Workspace, agentName string) (workspac
if len(agents) == 1 {
return agents[0], nil, nil
}
return codersdk.WorkspaceAgent{},nil, xerrors.Errorf("multiple agents found, please specify the agent name, available agents: %v", availableNames)
return codersdk.WorkspaceAgent{},agents, xerrors.Errorf("multiple agents found, please specify the agent name, available agents: %v", availableNames)
}

// Attempt to poll workspace autostop. We write a per-workspace lockfile to
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp