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
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commit320c906

Browse files
committed
Improve shell disconnect error
1 parent90dfe59 commit320c906

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

‎coder-sdk/env.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,28 @@ type CreateEnvironmentRequest struct {
7676
Services []string`json:"services"`
7777
}
7878

79+
// EnvironmentByName gets a single environment environment for the authenticted user by name.
80+
func (cClient)EnvironmentByName(ctx context.Context,namestring) (*Environment,error) {
81+
varenvEnvironment
82+
err:=c.requestBody(
83+
ctx,
84+
http.MethodGet,"/api/environments/"+name,
85+
nil,
86+
&env,
87+
)
88+
return&env,err
89+
}
90+
7991
// CreateEnvironment sends a request to create an environment.
8092
func (cClient)CreateEnvironment(ctx context.Context,orgIDstring,reqCreateEnvironmentRequest) (*Environment,error) {
81-
varenv*Environment
93+
varenvEnvironment
8294
err:=c.requestBody(
8395
ctx,
8496
http.MethodPost,"/api/orgs/"+orgID+"/environments",
8597
req,
86-
env,
98+
&env,
8799
)
88-
returnenv,err
100+
return&env,err
89101
}
90102

91103
// EnvironmentsByOrganization gets the list of environments owned by the given user.

‎internal/cmd/shell.go

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"context"
5+
"fmt"
56
"io"
67
"os"
78
"strings"
@@ -142,11 +143,7 @@ func runCommand(ctx context.Context, envName string, command string, args []stri
142143
Env:cmdEnv,
143144
})
144145
iferr!=nil {
145-
varcloseErr websocket.CloseError
146-
ifxerrors.As(err,&closeErr) {
147-
returnxerrors.Errorf("network error, is %q online?",envName)
148-
}
149-
returnerr
146+
returnprettyShellExitError(ctx,err,entClient,env.Name)
150147
}
151148

152149
iftty {
@@ -178,15 +175,36 @@ func runCommand(ctx context.Context, envName string, command string, args []stri
178175
}()
179176
err=process.Wait()
180177
iferr!=nil {
181-
varcloseErr websocket.CloseError
182-
ifxerrors.Is(err,ctx.Err())||xerrors.As(err,&closeErr) {
183-
returnxerrors.Errorf("network error, is %q online?",envName)
184-
}
185-
returnerr
178+
returnprettyShellExitError(ctx,err,entClient,env.Name)
186179
}
187180
returnnil
188181
}
189182

183+
funcprettyShellExitError(ctx context.Context,errerror,client*coder.Client,envNamestring)error {
184+
varcloseErr websocket.CloseError
185+
ifxerrors.Is(err,ctx.Err())||xerrors.As(err,&closeErr) {
186+
iferr!=nil {
187+
returnxerrors.Errorf("network error, %s",envErrorMessage(ctx,client,envName))
188+
}
189+
}
190+
returnerr
191+
}
192+
193+
funcenvErrorMessage(ctx context.Context,client*coder.Client,envNamestring)string {
194+
env,err:=client.EnvironmentByName(ctx,envName)
195+
iferr!=nil {
196+
returnfmt.Sprintf("failed to fetch environment status: %v",err)
197+
}
198+
ifenv.LatestStat.ContainerStatus=="" {
199+
return"environment status not found"
200+
}
201+
ifenv.LatestStat.ContainerStatus==coder.EnvironmentOn {
202+
returnfmt.Sprintf(`environment status is "%s", please try again`,env.LatestStat.ContainerStatus)
203+
}
204+
205+
returnfmt.Sprintf(`environment "%s" has a status of "%s"`,envName,env.LatestStat.ContainerStatus)
206+
}
207+
190208
funcheartbeat(ctx context.Context,c*websocket.Conn,interval time.Duration) {
191209
ticker:=time.NewTicker(interval)
192210
deferticker.Stop()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp