Skip to content

Commit 820711f

Browse files
authored
Merge pull request #527 from coderoad/feat/detect-failed-launch
Resolve failed launch on CodeAlly
2 parents 060ad10 + 055024e commit 820711f

File tree

10 files changed

+29
-15
lines changed

10 files changed

+29
-15
lines changed

‎src/actions/onStartup.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ const onStartup = async (context: Context): Promise<void> => {
4242
const tutorial = await tutorialRes.json()
4343
send({ type: 'START_TUTORIAL_FROM_URL', payload: { tutorial } })
4444
return
45-
} catch (e) {
45+
} catch (e: any) {
4646
// on failure to load a tutorial url fallback to NEW
47-
console.log(`Failed to load tutorial from url ${TUTORIAL_URL} with error "${e.message}"`)
47+
throw new Error(`Failed to load tutorial from url ${TUTORIAL_URL} with error "${e.message}"`)
4848
}
4949
}
5050
// NEW from start click
@@ -56,7 +56,7 @@ const onStartup = async (context: Context): Promise<void> => {
5656
const { position } = await context.onContinue(tutorial)
5757
// communicate to client the tutorial & stepProgress state
5858
send({ type: 'LOAD_STORED_TUTORIAL', payload: { env, tutorial, position } })
59-
} catch (e) {
59+
} catch (e: any) {
6060
const error = {
6161
type: 'UnknownError',
6262
message: `Location: Editor startup\n\n${e.message}`,

‎src/actions/onTutorialConfigContinue.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const onTutorialConfigContinue = async (action: T.Action, context: Context): Pro
2525
if (tutorialToContinue.config?.webhook) {
2626
setupWebhook(tutorialToContinue.config.webhook)
2727
}
28-
} catch (e) {
28+
} catch (e: any) {
2929
const error = {
3030
type: 'UnknownError',
3131
message: `Location: Editor tutorial continue config.\n\n ${e.message}`,

‎src/channel.ts

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class Channel implements Channel {
2020

2121
// receive from webview
2222
public receive = async (action: T.Action): Promise<void> => {
23+
if (action.source !== 'coderoad') {
24+
// filter out events from other extensions
25+
return
26+
}
27+
2328
// action may be an object.type or plain string
2429
const actionType: string = typeof action === 'string' ? action : action.type
2530

‎src/services/hooks/utils/openFiles.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const openFiles = async (files: string[] = []): Promise<void> => {
1515
const absoluteFilePath = join(wr, filePath)
1616
const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
1717
await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
18-
} catch (error) {
18+
} catch (error: any) {
1919
console.log(`Failed to open file ${filePath}: ${error.message}`)
2020
}
2121
}

‎src/services/hooks/utils/runCommands.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const runCommands = async (commands: string[] = []): Promise<void> => {
1515
try {
1616
result = await exec({ command })
1717
console.log(result)
18-
} catch (error) {
18+
} catch (error: any) {
1919
console.error(`Command failed: ${error.message}`)
2020
send({ type: 'COMMAND_FAIL', payload: { process: { ...process, status: 'FAIL' } } })
2121
return

‎src/services/reset/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const reset = async ({ branch, hash }: Input): Promise<void> => {
6363
await exec({
6464
command: `git reset --hard ${hash}`,
6565
})
66-
} catch (error) {
66+
} catch (error: any) {
6767
console.error('Error resetting')
6868
console.error(error.message)
6969
}

‎src/services/testRunner/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const createTestRunner = (data: TT.Tutorial, callbacks: Callbacks): ((params: an
7575
}
7676
logger('COMMAND', command)
7777
result = await exec({ command, dir: testRunnerConfig.directory })
78-
} catch (err) {
78+
} catch (err: any) {
7979
result = { stdout: err.stdout, stderr: err.stack }
8080
}
8181

‎src/services/webview/create.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ const createReactWebView = ({ extensionPath, channel }: ReactWebViewProps): Outp
5656

5757
// Handle messages from the webview
5858
const receive = channel.receive
59-
const send = (action: T.Action) => panel.webview.postMessage(action)
59+
const send = (action: T.Action) =>
60+
panel.webview.postMessage({
61+
...action,
62+
source: 'coderoad', // filter events on client by source. origin is not reliable
63+
})
6064

6165
panel.webview.onDidReceiveMessage(receive, null, disposables)
6266

‎typings/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export interface Position {
4949
// current tutorial state
5050

5151
export interface Action {
52+
source?: 'coderoad' // filter received actions by this
5253
type: string
5354
payload?: any
5455
meta?: any

‎web-app/src/services/state/useStateMachine.tsx

+10-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ declare let acquireVsCodeApi: any
1616
const editor = acquireVsCodeApi()
1717
const editorSend = (action: T.Action) => {
1818
logger(`TO EXT: "${action.type}"`)
19-
return editor.postMessage(action)
19+
return editor.postMessage({
20+
...action,
21+
source: 'coderoad', // filter events by source on editor side
22+
})
2023
}
2124

2225
// router finds first state match of <Route path='' />
@@ -31,14 +34,15 @@ const useStateMachine = (): Output => {
3134
// event bus listener
3235
React.useEffect(() => {
3336
const listener = 'message'
34-
// propograte channel event to state machine
37+
// propagate channel event to state machine
3538
const handler = (event: any) => {
36-
// ensure events are coming from coderoad webview
37-
if (!event.origin.match(/^vscode-webview/)) {
38-
return
39-
}
4039
// NOTE: must call event.data, cannot destructure. VSCode acts odd
4140
const action = event.data
41+
42+
if (action.source !== 'coderoad') {
43+
// filter out events from other extensions
44+
return
45+
}
4246
sendWithLog(action)
4347
}
4448
window.addEventListener(listener, handler)

0 commit comments

Comments
 (0)