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

Commitc8742ba

Browse files
authored
fix(cli): enhance error handling for multiple agents in SSH command (#19943)
Closes#19812## Problem> When I try to SSH into my workspace with multiple agents. It does notprovide an intuitive way to do that successfully and instead misguidesby printing wrong instructions.This PR enhances the error handling to provide suggestions with SSHcommands that users can copy and paste directly.Before:```Encountered an error running "coder ssh", see "coder ssh --help" for more informationerror: multiple agents found, please specify the agent name, available agents: [coder dev]```After:```Encountered an error running "coder ssh", see "coder ssh --help" for more informationerror: multiple agents found, please specify the agent name, available agents: [coder dev]Try running: $ ssh coder.dogfood.me.coder $ ssh dev.dogfood.me.coder```
1 parentda467ba commitc8742ba

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

‎cli/ssh.go‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,23 @@ func findWorkspaceAndAgentByHostname(
756756
hostname=strings.TrimSuffix(hostname,qualifiedSuffix)
757757
}
758758
hostname=normalizeWorkspaceInput(hostname)
759-
ws,agent,_,err:=GetWorkspaceAndAgent(ctx,inv,client,!disableAutostart,hostname)
759+
760+
ws,agent,otherAgents,err:=GetWorkspaceAndAgent(ctx,inv,client,!disableAutostart,hostname)
761+
iferr!=nil&&strings.Contains(err.Error(),"multiple agents found") {
762+
varerrorMsg strings.Builder
763+
_,_=errorMsg.WriteString(fmt.Sprintf("%s\nTry running:\n",err.Error()))
764+
for_,agent:=rangeotherAgents {
765+
switch {
766+
caseconfig.HostnameSuffix!="":
767+
_,_=errorMsg.WriteString(fmt.Sprintf("%s\n",cliui.Code(fmt.Sprintf("$ ssh %s.%s.%s.%s",agent.Name,ws.Name,ws.OwnerName,config.HostnameSuffix))))
768+
caseconfig.HostnamePrefix!="":
769+
_,_=errorMsg.WriteString(fmt.Sprintf("%s\n",cliui.Code(fmt.Sprintf("$ ssh %s%s.%s.%s",config.HostnamePrefix,agent.Name,ws.Name,ws.OwnerName))))
770+
default:
771+
_,_=errorMsg.WriteString(fmt.Sprintf("%s\n",cliui.Code(fmt.Sprintf("$ ssh %s.%s.%s",agent.Name,ws.Name,ws.OwnerName))))
772+
}
773+
}
774+
returnws,agent,xerrors.New(errorMsg.String())
775+
}
760776
returnws,agent,err
761777
}
762778

@@ -922,7 +938,7 @@ func GetWorkspaceAndAgent(ctx context.Context, inv *serpent.Invocation, client *
922938
}
923939
workspaceAgent,otherWorkspaceAgents,err:=getWorkspaceAgent(workspace,agentName)
924940
iferr!=nil {
925-
returncodersdk.Workspace{}, codersdk.WorkspaceAgent{},nil,err
941+
returnworkspace, codersdk.WorkspaceAgent{},otherWorkspaceAgents,err
926942
}
927943

928944
returnworkspace,workspaceAgent,otherWorkspaceAgents,nil
@@ -958,7 +974,7 @@ func getWorkspaceAgent(workspace codersdk.Workspace, agentName string) (workspac
958974
iflen(agents)==1 {
959975
returnagents[0],nil,nil
960976
}
961-
return codersdk.WorkspaceAgent{},nil,xerrors.Errorf("multiple agents found, please specify the agent name, available agents: %v",availableNames)
977+
return codersdk.WorkspaceAgent{},agents,xerrors.Errorf("multiple agents found, please specify the agent name, available agents: %v",availableNames)
962978
}
963979

964980
// Attempt to poll workspace autostop. We write a per-workspace lockfile to

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp