- Notifications
You must be signed in to change notification settings - Fork1k
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -756,7 +756,23 @@ func findWorkspaceAndAgentByHostname( | ||
hostname = strings.TrimSuffix(hostname, qualifiedSuffix) | ||
} | ||
hostname = normalizeWorkspaceInput(hostname) | ||
ws, agent, otherAgents, err := GetWorkspaceAndAgent(ctx, inv, client, !disableAutostart, hostname) | ||
if err != nil && strings.Contains(err.Error(), "multiple agents found") { | ||
Member
| ||
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 | ||
} | ||
@@ -922,7 +938,7 @@ func GetWorkspaceAndAgent(ctx context.Context, inv *serpent.Invocation, client * | ||
} | ||
workspaceAgent, otherWorkspaceAgents, err := getWorkspaceAgent(workspace, agentName) | ||
if err != nil { | ||
returnworkspace, codersdk.WorkspaceAgent{},otherWorkspaceAgents, err | ||
} | ||
return workspace, workspaceAgent, otherWorkspaceAgents, nil | ||
@@ -958,7 +974,7 @@ func getWorkspaceAgent(workspace codersdk.Workspace, agentName string) (workspac | ||
if len(agents) == 1 { | ||
return agents[0], nil, nil | ||
} | ||
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 | ||
Uh oh!
There was an error while loading.Please reload this page.