Skip to content

Resolve failed launch on CodeAlly #527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/actions/onStartup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ const onStartup = async (context: Context): Promise<void> => {
const tutorial = await tutorialRes.json()
send({ type: 'START_TUTORIAL_FROM_URL', payload: { tutorial } })
return
} catch (e) {
} catch (e: any) {
// on failure to load a tutorial url fallback to NEW
console.log(`Failed to load tutorial from url ${TUTORIAL_URL} with error "${e.message}"`)
throw new Error(`Failed to load tutorial from url ${TUTORIAL_URL} with error "${e.message}"`)
}
}
// NEW from start click
Expand All @@ -56,7 +56,7 @@ const onStartup = async (context: Context): Promise<void> => {
const { position } = await context.onContinue(tutorial)
// communicate to client the tutorial & stepProgress state
send({ type: 'LOAD_STORED_TUTORIAL', payload: { env, tutorial, position } })
} catch (e) {
} catch (e: any) {
const error = {
type: 'UnknownError',
message: `Location: Editor startup\n\n${e.message}`,
Expand Down
2 changes: 1 addition & 1 deletion src/actions/onTutorialConfigContinue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const onTutorialConfigContinue = async (action: T.Action, context: Context): Pro
if (tutorialToContinue.config?.webhook) {
setupWebhook(tutorialToContinue.config.webhook)
}
} catch (e) {
} catch (e: any) {
const error = {
type: 'UnknownError',
message: `Location: Editor tutorial continue config.\n\n ${e.message}`,
Expand Down
5 changes: 5 additions & 0 deletions src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class Channel implements Channel {

// receive from webview
public receive = async (action: T.Action): Promise<void> => {
if (action.source !== 'coderoad') {
// filter out events from other extensions
return
}

// action may be an object.type or plain string
const actionType: string = typeof action === 'string' ? action : action.type

Expand Down
2 changes: 1 addition & 1 deletion src/services/hooks/utils/openFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const openFiles = async (files: string[] = []): Promise<void> => {
const absoluteFilePath = join(wr, filePath)
const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
} catch (error) {
} catch (error: any) {
console.log(`Failed to open file ${filePath}: ${error.message}`)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/hooks/utils/runCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const runCommands = async (commands: string[] = []): Promise<void> => {
try {
result = await exec({ command })
console.log(result)
} catch (error) {
} catch (error: any) {
console.error(`Command failed: ${error.message}`)
send({ type: 'COMMAND_FAIL', payload: { process: { ...process, status: 'FAIL' } } })
return
Expand Down
2 changes: 1 addition & 1 deletion src/services/reset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const reset = async ({ branch, hash }: Input): Promise<void> => {
await exec({
command: `git reset --hard ${hash}`,
})
} catch (error) {
} catch (error: any) {
console.error('Error resetting')
console.error(error.message)
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/testRunner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const createTestRunner = (data: TT.Tutorial, callbacks: Callbacks): ((params: an
}
logger('COMMAND', command)
result = await exec({ command, dir: testRunnerConfig.directory })
} catch (err) {
} catch (err: any) {
result = { stdout: err.stdout, stderr: err.stack }
}

Expand Down
6 changes: 5 additions & 1 deletion src/services/webview/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ const createReactWebView = ({ extensionPath, channel }: ReactWebViewProps): Outp

// Handle messages from the webview
const receive = channel.receive
const send = (action: T.Action) => panel.webview.postMessage(action)
const send = (action: T.Action) =>
panel.webview.postMessage({
...action,
source: 'coderoad', // filter events on client by source. origin is not reliable
})

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

Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface Position {
// current tutorial state

export interface Action {
source?: 'coderoad' // filter received actions by this
type: string
payload?: any
meta?: any
Expand Down
16 changes: 10 additions & 6 deletions web-app/src/services/state/useStateMachine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ declare let acquireVsCodeApi: any
const editor = acquireVsCodeApi()
const editorSend = (action: T.Action) => {
logger(`TO EXT: "${action.type}"`)
return editor.postMessage(action)
return editor.postMessage({
...action,
source: 'coderoad', // filter events by source on editor side
})
}

// router finds first state match of <Route path='' />
Expand All @@ -31,14 +34,15 @@ const useStateMachine = (): Output => {
// event bus listener
React.useEffect(() => {
const listener = 'message'
// propograte channel event to state machine
// propagate channel event to state machine
const handler = (event: any) => {
// ensure events are coming from coderoad webview
if (!event.origin.match(/^vscode-webview/)) {
return
}
// NOTE: must call event.data, cannot destructure. VSCode acts odd
const action = event.data

if (action.source !== 'coderoad') {
// filter out events from other extensions
return
}
sendWithLog(action)
}
window.addEventListener(listener, handler)
Expand Down