@@ -49,49 +49,57 @@ class Channel implements Channel {
4949
5050switch ( actionType ) {
5151case 'EDITOR_STARTUP' :
52- // check if a workspace is open, otherwise nothing works
53- const noActiveWorksapce = ! WORKSPACE_ROOT . length
54- if ( noActiveWorksapce ) {
55- const error :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+ const noActiveWorksapce = ! WORKSPACE_ROOT . length
55+ if ( noActiveWorksapce ) {
56+ const error :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- const env = {
70- machineId :vscode . env . machineId ,
71- sessionId :vscode . env . sessionId ,
72- }
70+ const env = {
71+ machineId :vscode . env . machineId ,
72+ sessionId :vscode . env . sessionId ,
73+ }
7374
74- // continue from tutorial from local storage
75- const tutorial :TT . Tutorial | null = this . context . tutorial . get ( )
75+ // continue from tutorial from local storage
76+ const tutorial :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} = await this . context . setTutorial ( this . workspaceState , tutorial )
84+ // set tutorial
85+ const { position, progress} = await this . 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} } )
8995return
96+ } catch ( e ) {
97+ const error = {
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
97105case 'TUTORIAL_CLEAR' :
@@ -100,134 +108,159 @@ class Channel implements Channel {
100108return
101109// configure test runner, language, git
102110case 'EDITOR_TUTORIAL_CONFIG' :
103- const data :TT . Tutorial = action . payload . tutorial
104- // setup tutorial config (save watcher, test runner, etc)
105- await this . context . setTutorial ( this . workspaceState , data )
111+ try {
112+ const data :TT . Tutorial = action . payload . tutorial
113+ // setup tutorial config (save watcher, test runner, etc)
114+ await this . context . setTutorial ( this . workspaceState , data )
106115
107- // validate dependencies
108- const dependencies = data . config . dependencies
109- if ( dependencies && dependencies . length ) {
110- for ( const dep of dependencies ) {
111- // check dependency is installed
112- const currentVersion :string | null = await version ( dep . name )
113- if ( ! currentVersion ) {
114- // use a custom error message
115- const error = {
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+ const dependencies = data . config . dependencies
118+ if ( dependencies && dependencies . length ) {
119+ for ( const dep of dependencies ) {
120+ // check dependency is installed
121+ const currentVersion :string | null = await version ( dep . name )
122+ if ( ! currentVersion ) {
123+ // use a custom error message
124+ const error = {
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- const satisfiedDependency = await compareVersions ( currentVersion , dep . version )
139+ // check dependency version
140+ const satisfiedDependency = await compareVersions ( currentVersion , dep . version )
131141
132- if ( ! satisfiedDependency ) {
133- const error = {
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+ const error = {
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- const error = 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+ const error = 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- const error :E . ErrorMessage | void = await tutorialConfig ( { config :data . config } ) . catch ( ( error :Error ) => ( {
165- type :'UnknownError' ,
166- message :`Location: tutorial config.\n\n${ error . message } ` ,
167- } ) )
174+ const error :E . ErrorMessage | void = await tutorialConfig ( { 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' } )
172187return
188+ } catch ( e ) {
189+ const error = {
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
178195case 'EDITOR_TUTORIAL_CONTINUE_CONFIG' :
179- const tutorialContinue :TT . Tutorial | null = this . context . tutorial . get ( )
180- if ( ! tutorialContinue ) {
181- throw new Error ( 'Invalid tutorial to continue' )
196+ try {
197+ const tutorialContinue :TT . Tutorial | null = this . context . tutorial . get ( )
198+ if ( ! tutorialContinue ) {
199+ throw new Error ( 'Invalid tutorial to continue' )
200+ }
201+ const continueConfig :TT . TutorialConfig = tutorialContinue . config
202+ await tutorialConfig ( {
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+ const error = {
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- const continueConfig :TT . TutorialConfig = tutorialContinue . config
184- await tutorialConfig ( {
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
191216case 'EDITOR_VALIDATE_SETUP' :
192- // check workspace is selected
193- const isEmptyWorkspace = await checkWorkspaceEmpty ( )
194- if ( ! isEmptyWorkspace ) {
195- const error :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+ const isEmptyWorkspace = await checkWorkspaceEmpty ( )
220+ if ( ! isEmptyWorkspace ) {
221+ const error :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+ const isGitInstalled = await version ( 'git' )
241+ if ( ! isGitInstalled ) {
242+ const error :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' } )
210256return
211- }
212- // check Git is installed.
213- // Should wait for workspace before running otherwise requires access to root folder
214- const isGitInstalled = await version ( 'git' )
215- if ( ! isGitInstalled ) {
216- const error :E . ErrorMessage = {
217- type :'GitNotFound' ,
218- message :'' ,
219- actions :[
220- {
221- label :'Check Again' ,
222- transition :'RETRY' ,
223- } ,
224- ] ,
257+ } catch ( e ) {
258+ const error = {
259+ type :'UknownError' ,
260+ message :e . message ,
225261}
226262this . send ( { type :'VALIDATE_SETUP_FAILED' , payload :{ error} } )
227- return
228263}
229- this . send ( { type :'SETUP_VALIDATED' } )
230- return
231264case 'EDITOR_REQUEST_WORKSPACE' :
232265openWorkspace ( )
233266return