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

Commit8c88852

Browse files
authored
feat: auto update workspace if required by template (#233)
1 parent8850f8f commit8c88852

File tree

3 files changed

+63
-15
lines changed

3 files changed

+63
-15
lines changed

‎src/error.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import{isAxiosError}from"axios"
2+
import{isApiError,isApiErrorResponse}from"coder/site/src/api/errors"
23
import*asforgefrom"node-forge"
34
import*astlsfrom"tls"
45
import*asvscodefrom"vscode"
@@ -157,3 +158,14 @@ export class CertificateError extends Error {
157158
}
158159
}
159160
}
161+
162+
// getErrorDetail is copied from coder/site, but changes the default return.
163+
exportconstgetErrorDetail=(error:unknown):string|undefined|null=>{
164+
if(isApiError(error)){
165+
returnerror.response.data.detail
166+
}
167+
if(isApiErrorResponse(error)){
168+
returnerror.detail
169+
}
170+
returnnull
171+
}

‎src/extension.ts

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"use strict"
2-
importaxiosfrom"axios"
2+
importaxios,{isAxiosError}from"axios"
33
import{getAuthenticatedUser}from"coder/site/src/api/api"
4+
import{getErrorMessage}from"coder/site/src/api/errors"
45
importfsfrom"fs"
56
import*ashttpsfrom"https"
67
import*asmodulefrom"module"
78
import*asosfrom"os"
89
import*asvscodefrom"vscode"
910
import{Commands}from"./commands"
10-
import{CertificateError}from"./error"
11+
import{CertificateError,getErrorDetail}from"./error"
1112
import{Remote}from"./remote"
1213
import{Storage}from"./storage"
1314
import{WorkspaceQuery,WorkspaceProvider}from"./workspacesProvider"
@@ -199,13 +200,38 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
199200
try{
200201
awaitremote.setup(vscodeProposed.env.remoteAuthority)
201202
}catch(ex){
202-
if(exinstanceofCertificateError){
203-
returnawaitex.showModal("Failed to open workspace")
203+
switch(true){
204+
caseexinstanceofCertificateError:
205+
awaitex.showModal("Failed to open workspace")
206+
break
207+
caseisAxiosError(ex):
208+
{
209+
constmsg=getErrorMessage(ex,"")
210+
constdetail=getErrorDetail(ex)
211+
consturlString=axios.getUri(ex.response?.config)
212+
letpath=urlString
213+
try{
214+
path=newURL(urlString).pathname
215+
}catch(e){
216+
// ignore, default to full url
217+
}
218+
219+
awaitvscodeProposed.window.showErrorMessage("Failed to open workspace",{
220+
detail:`API${ex.response?.config.method?.toUpperCase()} to '${path}' failed with code${ex.response?.status}.\nMessage:${msg}\nDetail:${detail}`,
221+
modal:true,
222+
useCustom:true,
223+
})
224+
}
225+
break
226+
default:
227+
awaitvscodeProposed.window.showErrorMessage("Failed to open workspace",{
228+
detail:(exasstring).toString(),
229+
modal:true,
230+
useCustom:true,
231+
})
204232
}
205-
awaitvscodeProposed.window.showErrorMessage("Failed to open workspace",{
206-
detail:(exasstring).toString(),
207-
modal:true,
208-
useCustom:true,
209-
})
233+
234+
// Always close remote session when we fail to open a workspace.
235+
awaitremote.closeRemote()
210236
}
211237
}

‎src/remote.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,33 @@ export class Remote {
137137

138138
letbuildComplete:undefined|(()=>void)
139139
if(this.storage.workspace.latest_build.status==="stopped"){
140+
// If the workspace requires the latest active template version, we should attempt
141+
// to update that here.
142+
// TODO: If param set changes, what do we do??
143+
constversionID=this.storage.workspace.template_require_active_version
144+
?// Use the latest template version
145+
this.storage.workspace.template_active_version_id
146+
:// Default to not updating the workspace if not required.
147+
this.storage.workspace.latest_build.template_version_id
148+
140149
this.vscodeProposed.window.withProgress(
141150
{
142151
location:vscode.ProgressLocation.Notification,
143152
cancellable:false,
144-
title:"Starting workspace...",
153+
title:this.storage.workspace.template_require_active_version
154+
?"Updating workspace..."
155+
:"Starting workspace...",
145156
},
146157
()=>
147158
newPromise<void>((r)=>{
148159
buildComplete=r
149160
}),
150161
)
162+
163+
constlatestBuild=awaitstartWorkspace(this.storage.workspace.id,versionID)
151164
this.storage.workspace={
152165
...this.storage.workspace,
153-
latest_build:awaitstartWorkspace(
154-
this.storage.workspace.id,
155-
this.storage.workspace.latest_build.template_version_id,
156-
),
166+
latest_build:latestBuild,
157167
}
158168
}
159169

@@ -796,7 +806,7 @@ export class Remote {
796806
}
797807

798808
// closeRemote ends the current remote session.
799-
privateasynccloseRemote(){
809+
publicasynccloseRemote(){
800810
awaitvscode.commands.executeCommand("workbench.action.remote.close")
801811
}
802812

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp