@@ -4,25 +4,20 @@ import * as E from 'typings/error'
44import * as vscode from 'vscode'
55import fetch from 'node-fetch'
66import { satisfies } from 'semver'
7- import saveCommit from '../actions/saveCommit'
8- import { setupActions , solutionActions } from '../actions/setupActions'
9- import tutorialConfig from '../actions/tutorialConfig'
10- import { COMMANDS } from '../editor/commands'
11- import Context from './context'
12- import { readFile } from 'fs'
13- import { join } from 'path'
14- import { promisify } from 'util'
15- import logger from '../services/logger'
16- import { version , compareVersions } from '../services/dependencies'
17- import { openWorkspace , checkWorkspaceEmpty } from '../services/workspace'
18- import { showOutput } from '../services/testRunner/output'
19- import { exec } from '../services/node'
20- import { WORKSPACE_ROOT , TUTORIAL_URL } from '../environment'
21- import reset from '../services/reset'
22- import getLastCommitHash from '../services/reset/lastHash'
23- import { onEvent } from '../services/telemetry'
24-
25- const readFileAsync = promisify ( readFile )
7+ import { setupActions , solutionActions } from './actions/setupActions'
8+ import tutorialConfig from './actions/tutorialConfig'
9+ import { COMMANDS } from './commands'
10+ import Context from './services/context/context'
11+ import logger from './services/logger'
12+ import { version , compareVersions } from './services/dependencies'
13+ import { openWorkspace , checkWorkspaceEmpty } from './services/workspace'
14+ import { showOutput } from './services/testRunner/output'
15+ import { exec } from './services/node'
16+ import { WORKSPACE_ROOT , TUTORIAL_URL } from './environment'
17+ import reset from './services/reset'
18+ import getLastCommitHash from './services/reset/lastHash'
19+ import { onEvent } from './services/telemetry'
20+ import * as actions from './actions'
2621
2722interface Channel {
2823receive ( action :T . Action ) :Promise < void >
@@ -359,39 +354,16 @@ class Channel implements Channel {
359354}
360355// send to webview
361356public send = async ( action :T . Action ) :Promise < void > => {
362- // Error middleware
363- if ( action ?. payload ?. error ?. type ) {
364- // load error markdown message
365- const error = action . payload . error
366- const errorMarkdownFile = join ( __dirname , '..' , '..' , 'errors' , `${ action . payload . error . type } .md` )
367- const errorMarkdown = await readFileAsync ( errorMarkdownFile ) . catch ( ( ) => {
368- // onError(new Error(`Error Markdown file not found for ${action.type}`))
369- } )
370-
371- // log error to console for safe keeping
372- logger ( `ERROR:\n${ errorMarkdown } ` )
373-
374- if ( errorMarkdown ) {
375- // add a clearer error message for the user
376- error . message = `${ errorMarkdown } \n\n${ error . message } `
377- }
378- }
379-
357+ // load error page if error action is triggered
358+ actions . onErrorPage ( action )
380359// action may be an object.type or plain string
381360const actionType :string = typeof action === 'string' ?action :action . type
382361
383362logger ( `EXT TO CLIENT: "${ actionType } "` )
384363
385364switch ( actionType ) {
386365case 'TEST_PASS' :
387- const tutorial = this . context . tutorial . get ( )
388- if ( ! tutorial ) {
389- throw new Error ( 'Error with current tutorial. Tutorial may be missing an id.' )
390- }
391- // update local storage stepProgress
392- const progress = this . context . progress . setStepComplete ( tutorial , action . payload . position . stepId )
393- this . context . position . setPositionFromProgress ( tutorial , progress )
394- saveCommit ( )
366+ actions . onTestPass ( action , this . context )
395367}
396368
397369// send message