Skip to content

Feature/capture errors #61

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 5 commits into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/actions/tutorialConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as T from 'typings'
import * as G from 'typings/graphql'
import * as vscode from 'vscode'
import * as git from '../services/git'
Expand All @@ -10,13 +11,25 @@ interface TutorialConfigParams {
onComplete?(): void
}

const tutorialConfig = async ({ config, alreadyConfigured }: TutorialConfigParams) => {
const tutorialConfig = async (
{ config, alreadyConfigured }: TutorialConfigParams,
onError: (msg: T.ErrorMessage) => void,
) => {
if (!alreadyConfigured) {
// setup git, add remote
await git.initIfNotExists()
await git.initIfNotExists().catch(error => {
// failed to setup git
onError({
title: error.message,
description:
'Be sure you install Git. See the docs for help https://git-scm.com/book/en/v2/Getting-Started-Installing-Git',
})
})

// TODO: if remote not already set
await git.setupRemote(config.repo.uri)
await git.setupRemote(config.repo.uri).catch(error => {
onError({ title: error.message, description: 'Remove your current Git project and restarting' })
})
}

vscode.commands.executeCommand(COMMANDS.CONFIG_TEST_RUNNER, config.testRunner)
Expand Down
1 change: 0 additions & 1 deletion src/actions/utils/runCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const runCommands = async (commands: string[], send: (action: T.Action) => void)
send({ type: 'COMMAND_FAIL', payload: { process: { ...process, status: 'FAIL' } } })
return
}
console.log(result.stdout)
send({ type: 'COMMAND_SUCCESS', payload: { process: { ...process, status: 'SUCCESS' } } })
}
}
Expand Down
30 changes: 16 additions & 14 deletions src/channel/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as CR from 'typings'
import * as T from 'typings'
import * as G from 'typings/graphql'
import * as vscode from 'vscode'

Expand All @@ -10,18 +10,18 @@ import saveCommit from '../actions/saveCommit'
import { COMMANDS } from '../editor/commands'

interface Channel {
receive(action: CR.Action): Promise<void>
send(action: CR.Action): Promise<void>
receive(action: T.Action): Promise<void>
send(action: T.Action): Promise<void>
}

interface ChannelProps {
postMessage: (action: CR.Action) => Thenable<boolean>
postMessage: (action: T.Action) => Thenable<boolean>
workspaceState: vscode.Memento
workspaceRoot: vscode.WorkspaceFolder
}

class Channel implements Channel {
private postMessage: (action: CR.Action) => Thenable<boolean>
private postMessage: (action: T.Action) => Thenable<boolean>
private workspaceState: vscode.Memento
private workspaceRoot: vscode.WorkspaceFolder
private context: Context
Expand All @@ -34,11 +34,11 @@ class Channel implements Channel {
}

// receive from webview
public receive = async (action: CR.Action) => {
public receive = async (action: T.Action) => {
// action may be an object.type or plain string
const actionType: string = typeof action === 'string' ? action : action.type
const onError = (error: T.ErrorMessage) => this.send({ type: 'ERROR', payload: { error } })

// console.log('EDITOR RECEIVED:', actionType)
switch (actionType) {
case 'ENV_GET':
this.send({
Expand Down Expand Up @@ -87,7 +87,7 @@ class Channel implements Channel {

const data: G.TutorialData = tutorialData.version.data

await tutorialConfig({ config: data.config })
await tutorialConfig({ config: data.config }, onError)

// run init setup actions
if (data.init) {
Expand All @@ -106,10 +106,13 @@ class Channel implements Channel {
throw new Error('Invalid tutorial to continue')
}
const continueConfig: G.TutorialConfig = tutorialContinue.version.data.config
tutorialConfig({
config: continueConfig,
alreadyConfigured: true,
})
tutorialConfig(
{
config: continueConfig,
alreadyConfigured: true,
},
onError,
)
return
case 'EDITOR_SYNC_PROGRESS':
// sync client progress on server
Expand All @@ -134,8 +137,7 @@ class Channel implements Channel {
}
}
// send to webview
public send = async (action: CR.Action) => {
console.log(`EDITOR SEND ${action.type}`)
public send = async (action: T.Action) => {
// action may be an object.type or plain string
const actionType: string = typeof action === 'string' ? action : action.type
switch (actionType) {
Expand Down
189 changes: 0 additions & 189 deletions src/editor/ReactWebView.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/editor/commands.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as G from 'typings/graphql'
import * as vscode from 'vscode'
import ReactWebView from './ReactWebView'
import createWebView from '../webview'
import createTestRunner, { Payload } from '../services/testRunner'

export const COMMANDS = {
Expand Down Expand Up @@ -41,7 +41,7 @@ export const createCommands = ({ extensionPath, workspaceState, workspaceRoot }:
}

// activate machine
webview = new ReactWebView({
webview = createWebView({
extensionPath,
workspaceState,
workspaceRoot,
Expand Down
4 changes: 3 additions & 1 deletion src/services/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export async function version(): Promise<string | boolean> {
async function init(): Promise<void> {
const { stderr } = await node.exec('git init')
if (stderr) {
throw new Error('Error initializing Gits')
throw new Error('Error initializing Git')
}
}

Expand Down Expand Up @@ -133,5 +133,7 @@ export async function setupRemote(repo: string): Promise<void> {
// git fetch coderoad
if (!hasRemote) {
await addRemote(repo)
} else {
throw new Error('A Remote is already configured')
}
}
Loading