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

Commite55e799

Browse files
authored
Merge pull request#263 from coderoad/error-handling
increased unknown error handling
2 parents24b0dcd +5de3c97 commite55e799

File tree

2 files changed

+182
-142
lines changed

2 files changed

+182
-142
lines changed

‎src/channel/index.ts

Lines changed: 175 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -49,49 +49,57 @@ class Channel implements Channel {
4949

5050
switch(actionType){
5151
case'EDITOR_STARTUP':
52-
// check if a workspace is open, otherwise nothing works
53-
constnoActiveWorksapce=!WORKSPACE_ROOT.length
54-
if(noActiveWorksapce){
55-
consterror:E.ErrorMessage={
56-
type:'NoWorkspaceFound',
57-
message:'',
58-
actions:[
59-
{
60-
label:'Open Workspace',
61-
transition:'REQUEST_WORKSPACE',
62-
},
63-
],
52+
try{
53+
// check if a workspace is open, otherwise nothing works
54+
constnoActiveWorksapce=!WORKSPACE_ROOT.length
55+
if(noActiveWorksapce){
56+
consterror:E.ErrorMessage={
57+
type:'NoWorkspaceFound',
58+
message:'',
59+
actions:[
60+
{
61+
label:'Open Workspace',
62+
transition:'REQUEST_WORKSPACE',
63+
},
64+
],
65+
}
66+
this.send({type:'NO_WORKSPACE',payload:{ error}})
67+
return
6468
}
65-
this.send({type:'NO_WORKSPACE',payload:{ error}})
66-
return
67-
}
6869

69-
constenv={
70-
machineId:vscode.env.machineId,
71-
sessionId:vscode.env.sessionId,
72-
}
70+
constenv={
71+
machineId:vscode.env.machineId,
72+
sessionId:vscode.env.sessionId,
73+
}
7374

74-
// continue from tutorial from local storage
75-
consttutorial:TT.Tutorial|null=this.context.tutorial.get()
75+
// continue from tutorial from local storage
76+
consttutorial:TT.Tutorial|null=this.context.tutorial.get()
7677

77-
// new tutorial
78-
if(!tutorial||!tutorial.id){
79-
this.send({type:'START_NEW_TUTORIAL',payload:{ env}})
80-
return
81-
}
78+
// new tutorial
79+
if(!tutorial||!tutorial.id){
80+
this.send({type:'START_NEW_TUTORIAL',payload:{ env}})
81+
return
82+
}
8283

83-
// set tutorial
84-
const{ position, progress}=awaitthis.context.setTutorial(this.workspaceState,tutorial)
84+
// set tutorial
85+
const{ position, progress}=awaitthis.context.setTutorial(this.workspaceState,tutorial)
86+
87+
if(progress.complete){
88+
// tutorial is already complete
89+
this.send({type:'TUTORIAL_ALREADY_COMPLETE',payload:{ env}})
90+
return
91+
}
92+
// communicate to client the tutorial & stepProgress state
93+
this.send({type:'LOAD_STORED_TUTORIAL',payload:{ env, tutorial, progress, position}})
8594

86-
if(progress.complete){
87-
// tutorial is already complete
88-
this.send({type:'TUTORIAL_ALREADY_COMPLETE',payload:{ env}})
8995
return
96+
}catch(e){
97+
consterror={
98+
type:'UnknownError',
99+
message:`Location: Editor startup\n\n${e.message}`,
100+
}
101+
this.send({type:'EDITOR_STARTUP_FAILED',payload:{ error}})
90102
}
91-
// communicate to client the tutorial & stepProgress state
92-
this.send({type:'LOAD_STORED_TUTORIAL',payload:{ env, tutorial, progress, position}})
93-
94-
return
95103

96104
// clear tutorial local storage
97105
case'TUTORIAL_CLEAR':
@@ -100,134 +108,159 @@ class Channel implements Channel {
100108
return
101109
// configure test runner, language, git
102110
case'EDITOR_TUTORIAL_CONFIG':
103-
constdata:TT.Tutorial=action.payload.tutorial
104-
// setup tutorial config (save watcher, test runner, etc)
105-
awaitthis.context.setTutorial(this.workspaceState,data)
111+
try{
112+
constdata:TT.Tutorial=action.payload.tutorial
113+
// setup tutorial config (save watcher, test runner, etc)
114+
awaitthis.context.setTutorial(this.workspaceState,data)
106115

107-
// validate dependencies
108-
constdependencies=data.config.dependencies
109-
if(dependencies&&dependencies.length){
110-
for(constdepofdependencies){
111-
// check dependency is installed
112-
constcurrentVersion:string|null=awaitversion(dep.name)
113-
if(!currentVersion){
114-
// use a custom error message
115-
consterror={
116-
type:'MissingTutorialDependency',
117-
message:dep.message||`Process "${dep.name}" is required but not found. It may need to be installed`,
118-
actions:[
119-
{
120-
label:'Check Again',
121-
transition:'TRY_AGAIN',
122-
},
123-
],
116+
// validate dependencies
117+
constdependencies=data.config.dependencies
118+
if(dependencies&&dependencies.length){
119+
for(constdepofdependencies){
120+
// check dependency is installed
121+
constcurrentVersion:string|null=awaitversion(dep.name)
122+
if(!currentVersion){
123+
// use a custom error message
124+
consterror={
125+
type:'MissingTutorialDependency',
126+
message:
127+
dep.message||`Process "${dep.name}" is required but not found. It may need to be installed`,
128+
actions:[
129+
{
130+
label:'Check Again',
131+
transition:'TRY_AGAIN',
132+
},
133+
],
134+
}
135+
this.send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
136+
return
124137
}
125-
this.send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
126-
return
127-
}
128138

129-
// check dependency version
130-
constsatisfiedDependency=awaitcompareVersions(currentVersion,dep.version)
139+
// check dependency version
140+
constsatisfiedDependency=awaitcompareVersions(currentVersion,dep.version)
131141

132-
if(!satisfiedDependency){
133-
consterror={
134-
type:'UnmetTutorialDependency',
135-
message:`Expected${dep.name} to have version${dep.version}, but found version${currentVersion}`,
136-
actions:[
137-
{
138-
label:'Check Again',
139-
transition:'TRY_AGAIN',
140-
},
141-
],
142+
if(!satisfiedDependency){
143+
consterror={
144+
type:'UnmetTutorialDependency',
145+
message:`Expected${dep.name} to have version${dep.version}, but found version${currentVersion}`,
146+
actions:[
147+
{
148+
label:'Check Again',
149+
transition:'TRY_AGAIN',
150+
},
151+
],
152+
}
153+
this.send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
154+
return
142155
}
143-
this.send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
144-
return
145-
}
146156

147-
if(satisfiedDependency!==true){
148-
consterror=satisfiedDependency||{
149-
type:'UnknownError',
150-
message:`Something went wrong comparing dependency for${name}`,
151-
actions:[
152-
{
153-
label:'Try Again',
154-
transition:'TRY_AGAIN',
155-
},
156-
],
157+
if(satisfiedDependency!==true){
158+
consterror=satisfiedDependency||{
159+
type:'UnknownError',
160+
message:`Something went wrong comparing dependency for${name}`,
161+
actions:[
162+
{
163+
label:'Try Again',
164+
transition:'TRY_AGAIN',
165+
},
166+
],
167+
}
168+
this.send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
169+
return
157170
}
158-
this.send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
159-
return
160171
}
161172
}
162-
}
163173

164-
consterror:E.ErrorMessage|void=awaittutorialConfig({config:data.config}).catch((error:Error)=>({
165-
type:'UnknownError',
166-
message:`Location: tutorial config.\n\n${error.message}`,
167-
}))
174+
consterror:E.ErrorMessage|void=awaittutorialConfig({config:data.config}).catch((error:Error)=>({
175+
type:'UnknownError',
176+
message:`Location: tutorial config.\n\n${error.message}`,
177+
}))
168178

169-
// has error
170-
if(error&&error.type){
171-
this.send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
179+
// has error
180+
if(error&&error.type){
181+
this.send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
182+
return
183+
}
184+
185+
// report back to the webview that setup is complete
186+
this.send({type:'TUTORIAL_CONFIGURED'})
172187
return
188+
}catch(e){
189+
consterror={
190+
type:'UnknownError',
191+
message:`Location: EditorTutorialConfig.\n\n${e.message}`,
192+
}
193+
this.send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
173194
}
174-
175-
// report back to the webview that setup is complete
176-
this.send({type:'TUTORIAL_CONFIGURED'})
177-
return
178195
case'EDITOR_TUTORIAL_CONTINUE_CONFIG':
179-
consttutorialContinue:TT.Tutorial|null=this.context.tutorial.get()
180-
if(!tutorialContinue){
181-
thrownewError('Invalid tutorial to continue')
196+
try{
197+
consttutorialContinue:TT.Tutorial|null=this.context.tutorial.get()
198+
if(!tutorialContinue){
199+
thrownewError('Invalid tutorial to continue')
200+
}
201+
constcontinueConfig:TT.TutorialConfig=tutorialContinue.config
202+
awaittutorialConfig({
203+
config:continueConfig,
204+
alreadyConfigured:true,
205+
})
206+
// update the current stepId on startup
207+
vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP,action.payload)
208+
return
209+
}catch(e){
210+
consterror={
211+
type:'UnknownError',
212+
message:`Location: Editor tutorial continue config.\n\n${e.message}`,
213+
}
214+
this.send({type:'CONTINUE_FAILED',payload:{ error}})
182215
}
183-
constcontinueConfig:TT.TutorialConfig=tutorialContinue.config
184-
awaittutorialConfig({
185-
config:continueConfig,
186-
alreadyConfigured:true,
187-
})
188-
// update the current stepId on startup
189-
vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP,action.payload)
190-
return
191216
case'EDITOR_VALIDATE_SETUP':
192-
// check workspace is selected
193-
constisEmptyWorkspace=awaitcheckWorkspaceEmpty()
194-
if(!isEmptyWorkspace){
195-
consterror:E.ErrorMessage={
196-
type:'WorkspaceNotEmpty',
197-
message:'',
198-
actions:[
199-
{
200-
label:'Open Workspace',
201-
transition:'REQUEST_WORKSPACE',
202-
},
203-
{
204-
label:'Check Again',
205-
transition:'RETRY',
206-
},
207-
],
217+
try{
218+
// check workspace is selected
219+
constisEmptyWorkspace=awaitcheckWorkspaceEmpty()
220+
if(!isEmptyWorkspace){
221+
consterror:E.ErrorMessage={
222+
type:'WorkspaceNotEmpty',
223+
message:'',
224+
actions:[
225+
{
226+
label:'Open Workspace',
227+
transition:'REQUEST_WORKSPACE',
228+
},
229+
{
230+
label:'Check Again',
231+
transition:'RETRY',
232+
},
233+
],
234+
}
235+
this.send({type:'VALIDATE_SETUP_FAILED',payload:{ error}})
236+
return
208237
}
209-
this.send({type:'VALIDATE_SETUP_FAILED',payload:{ error}})
238+
// check Git is installed.
239+
// Should wait for workspace before running otherwise requires access to root folder
240+
constisGitInstalled=awaitversion('git')
241+
if(!isGitInstalled){
242+
consterror:E.ErrorMessage={
243+
type:'GitNotFound',
244+
message:'',
245+
actions:[
246+
{
247+
label:'Check Again',
248+
transition:'RETRY',
249+
},
250+
],
251+
}
252+
this.send({type:'VALIDATE_SETUP_FAILED',payload:{ error}})
253+
return
254+
}
255+
this.send({type:'SETUP_VALIDATED'})
210256
return
211-
}
212-
// check Git is installed.
213-
// Should wait for workspace before running otherwise requires access to root folder
214-
constisGitInstalled=awaitversion('git')
215-
if(!isGitInstalled){
216-
consterror:E.ErrorMessage={
217-
type:'GitNotFound',
218-
message:'',
219-
actions:[
220-
{
221-
label:'Check Again',
222-
transition:'RETRY',
223-
},
224-
],
257+
}catch(e){
258+
consterror={
259+
type:'UknownError',
260+
message:e.message,
225261
}
226262
this.send({type:'VALIDATE_SETUP_FAILED',payload:{ error}})
227-
return
228263
}
229-
this.send({type:'SETUP_VALIDATED'})
230-
return
231264
case'EDITOR_REQUEST_WORKSPACE':
232265
openWorkspace()
233266
return

‎web-app/src/services/state/machine.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export const createMachine = (options: any) => {
3737
onEntry:['startup'],
3838
onExit:['clearError'],
3939
on:{
40+
EDITOR_STARTUP_FAILED:{
41+
actions:['setError'],
42+
},
4043
NO_WORKSPACE:{
4144
actions:['setError'],
4245
},
@@ -74,12 +77,16 @@ export const createMachine = (options: any) => {
7477
},
7578
},
7679
Start:{
80+
onExit:['clearError'],
7781
on:{
7882
NEW_TUTORIAL:'ValidateSetup',
7983
CONTINUE_TUTORIAL:{
8084
target:'#tutorial-level',
8185
actions:['continueConfig'],
8286
},
87+
CONTINUE_FAILED:{
88+
actions:['setError'],
89+
},
8390
},
8491
},
8592
SelectTutorial:{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp