Skip to content

Commit da99a1b

Browse files
committed
Ensure codespace exists and doesn't have a pending op when opening Code
The initial intention for this change was to disallow users to open a codespace in VS Code if the codespace has a pending operation. This also adds a side-benefit of presenting the user an error before waiting for VS Code to open if they provide an invalid codespace to open.
1 parent 599c7c9 commit da99a1b

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

pkg/cmd/codespace/code.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,19 @@ func newCodeCmd(app *App) *cobra.Command {
3131

3232
// VSCode opens a codespace in the local VS VSCode application.
3333
func (a *App) VSCode(ctx context.Context, codespaceName string, useInsiders bool) error {
34-
if codespaceName == "" {
35-
codespace, err := chooseCodespace(ctx, a.apiClient)
36-
if err != nil {
37-
if err == errNoCodespaces {
38-
return err
39-
}
40-
return fmt.Errorf("error choosing codespace: %w", err)
41-
}
42-
codespaceName = codespace.Name
34+
codespace, err := getOrChooseCodespace(ctx, a.apiClient, codespaceName)
35+
if err != nil {
36+
return fmt.Errorf("get or choose codespace: %w", err)
4337
}
4438

45-
url := vscodeProtocolURL(codespaceName, useInsiders)
39+
if codespace.PendingOperation {
40+
return fmt.Errorf(
41+
"codespace is disabled while it has a pending operation: %s",
42+
codespace.PendingOperationDisabledReason,
43+
)
44+
}
45+
46+
url := vscodeProtocolURL(codespace.Name, useInsiders)
4647
if err := a.browser.Browse(url); err != nil {
4748
return fmt.Errorf("error opening Visual Studio Code: %w", err)
4849
}

0 commit comments

Comments
 (0)