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.
This commit is contained in:
parent
599c7c900f
commit
da99a1b59b
1 changed files with 11 additions and 10 deletions
|
|
@ -31,18 +31,19 @@ func newCodeCmd(app *App) *cobra.Command {
|
|||
|
||||
// VSCode opens a codespace in the local VS VSCode application.
|
||||
func (a *App) VSCode(ctx context.Context, codespaceName string, useInsiders bool) error {
|
||||
if codespaceName == "" {
|
||||
codespace, err := chooseCodespace(ctx, a.apiClient)
|
||||
if err != nil {
|
||||
if err == errNoCodespaces {
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("error choosing codespace: %w", err)
|
||||
}
|
||||
codespaceName = codespace.Name
|
||||
codespace, err := getOrChooseCodespace(ctx, a.apiClient, codespaceName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get or choose codespace: %w", err)
|
||||
}
|
||||
|
||||
url := vscodeProtocolURL(codespaceName, useInsiders)
|
||||
if codespace.PendingOperation {
|
||||
return fmt.Errorf(
|
||||
"codespace is disabled while it has a pending operation: %s",
|
||||
codespace.PendingOperationDisabledReason,
|
||||
)
|
||||
}
|
||||
|
||||
url := vscodeProtocolURL(codespace.Name, useInsiders)
|
||||
if err := a.browser.Browse(url); err != nil {
|
||||
return fmt.Errorf("error opening Visual Studio Code: %w", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue