@@ -68,8 +68,9 @@ func shCmd() *cobra.Command {
68
68
return & cobra.Command {
69
69
Use : "sh [environment_name] [<command [args...]>]" ,
70
70
Short : "Open a shell and execute commands in a Coder environment" ,
71
- Long : "Execute a remote command on the environment\\ nIf no command is specified, the default shell is opened.\\ n" +
72
- "If the command is run in an interactive shell, a user prompt will occur if the environment needs to be rebuilt." ,
71
+ Long : `Execute a remote command on the environment
72
+ If no command is specified, the default shell is opened.
73
+ If the command is run in an interactive shell, a user prompt will occur if the environment needs to be rebuilt.` ,
73
74
Args : shValidArgs ,
74
75
DisableFlagParsing : true ,
75
76
ValidArgsFunction : getEnvsForCompletion (coder .Me ),
@@ -138,7 +139,6 @@ func rebuildPrompt(env *coder.Environment) (prompt func() error) {
138
139
_ , err = confirm .Run ()
139
140
return
140
141
}
141
-
142
142
}
143
143
144
144
// Option 2: If there are required rebuild messages, the rebuild is needed
@@ -175,6 +175,7 @@ func rebuildPrompt(env *coder.Environment) (prompt func() error) {
175
175
// - Environment is offline
176
176
// - Environment has rebuild messages requiring a rebuild
177
177
func checkAndRebuildEnvironment (ctx context.Context , client * coder.Client , env * coder.Environment ) error {
178
+ var err error
178
179
rebuildPrompt := rebuildPrompt (env ) // Fetch the prompt for rebuilding envs w/ reason
179
180
180
181
switch {
@@ -221,15 +222,33 @@ func checkAndRebuildEnvironment(ctx context.Context, client *coder.Client, env *
221
222
// newline after trailBuildLogs to place user on a fresh line for their shell
222
223
fmt .Println ()
223
224
224
- // Ensure the env is actually 'ON' after the rebuild. Timeout after
225
- // `maxWait`
226
- status , err := waitForEnvOnline (ctx , client , env .ID , maxWait )
225
+ // At this point the buildlog is complete, and the status of the env should be 'ON'
226
+ env , err = client .EnvironmentByID (ctx , env .ID )
227
+ if err != nil {
228
+ // If this api call failed, it will likely fail again, no point to retry and make the user wait
229
+ return err
230
+ }
231
+
232
+ // Get a nice error based on the status
233
+ switch env .LatestStat .ContainerStatus {
234
+ case coder .EnvironmentOn :
235
+ // This is the case we expect, just making it explicit
236
+ case coder .EnvironmentOff :
237
+ err = fmt .Errorf ("environment %q is off and will not come online" , env .Name )
238
+ case coder .EnvironmentFailed :
239
+ err = fmt .Errorf ("environment %q has failed to build and will not come online" , env .Name )
240
+ case coder .EnvironmentCreating :
241
+ // This should never happen
242
+ err = fmt .Errorf ("environment %q did not finish being created" , env .Name )
243
+ default :
244
+ err = fmt .Errorf ("environment %q has run into an unknown issue" , env .Name )
245
+ }
246
+
227
247
if err != nil {
228
248
// This means we had a timeout
229
249
return clog .Fatal ("the environment rebuild ran into an issue" ,
230
- fmt .Sprintf ("timed out waiting for environment %q to come online" , env .Name ),
231
- fmt .Sprintf ("its current status is %q" , status ),
232
- "if the container is still being created, it might still come online after some time" ,
250
+ err .Error (),
251
+ fmt .Sprintf ("its current status is %q" , env .LatestStat .ContainerStatus ),
233
252
clog .BlankLine ,
234
253
// TODO: (@emyrk) can they check these logs from the cli? Isn't this the logs that
235
254
// I just showed them? I'm trying to decide what exactly to tell a user.
0 commit comments