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 1 commit
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
Next Next commit
track git config errors
  • Loading branch information
ShMcK committed Nov 24, 2019
commit e0185840ccbe020f46e332ad4c1c44e591be586c
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
28 changes: 16 additions & 12 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,9 +34,10 @@ 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) {
Expand Down Expand Up @@ -87,7 +88,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 +107,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,7 +138,7 @@ class Channel implements Channel {
}
}
// send to webview
public send = async (action: CR.Action) => {
public send = async (action: T.Action) => {
console.log(`EDITOR SEND ${action.type}`)
// action may be an object.type or plain string
const actionType: string = typeof action === 'string' ? action : action.type
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')
}
}
216 changes: 108 additions & 108 deletions web-app/src/containers/Tutorial/LevelPage/Level.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,124 +8,124 @@ import Markdown from '../../../components/Markdown'
import ProcessEvents from '../../../components/ProcessEvents'

const styles = {
page: {
backgroundColor: 'white',
position: 'relative' as 'relative',
display: 'flex' as 'flex',
flexDirection: 'column' as 'column',
padding: 0,
paddingBottom: '36px',
height: 'auto',
width: '100%',
},
header: {
height: '36px',
backgroundColor: '#EBEBEB',
fontSize: '16px',
lineHeight: '16px',
padding: '10px 1rem',
},
content: {
padding: '0rem 1rem',
paddingBottom: '1rem',
},
tasks: {
paddingBottom: '5rem',
},
steps: {
padding: '1rem 16px',
},
title: {
fontSize: '1.2rem',
fontWeight: 'bold' as 'bold',
lineHeight: '1.2rem',
},
processes: {
padding: '0 1rem',
position: 'absolute' as 'absolute',
bottom: '36px',
},
footer: {
display: 'flex' as 'flex',
flexDirection: 'row' as 'row',
justifyContent: 'space-between',
alignItems: 'center',
height: '36px',
backgroundColor: 'black',
fontSize: '16px',
lineHeight: '16px',
padding: '10px 1rem',
position: 'fixed' as 'fixed',
bottom: 0,
left: 0,
right: 0,
color: 'white',
},
page: {
backgroundColor: 'white',
position: 'relative' as 'relative',
display: 'flex' as 'flex',
flexDirection: 'column' as 'column',
padding: 0,
paddingBottom: '36px',
height: 'auto',
width: '100%',
},
header: {
height: '36px',
backgroundColor: '#EBEBEB',
fontSize: '16px',
lineHeight: '16px',
padding: '10px 1rem',
},
content: {
padding: '0rem 1rem',
paddingBottom: '1rem',
},
tasks: {
paddingBottom: '5rem',
},
steps: {
padding: '1rem 16px',
},
title: {
fontSize: '1.2rem',
fontWeight: 'bold' as 'bold',
lineHeight: '1.2rem',
},
processes: {
padding: '0 1rem',
position: 'absolute' as 'absolute',
bottom: '36px',
},
footer: {
display: 'flex' as 'flex',
flexDirection: 'row' as 'row',
justifyContent: 'space-between',
alignItems: 'center',
height: '36px',
backgroundColor: 'black',
fontSize: '16px',
lineHeight: '16px',
padding: '10px 1rem',
position: 'fixed' as 'fixed',
bottom: 0,
left: 0,
right: 0,
color: 'white',
},
}

interface Props {
level: G.Level & { status: T.ProgressStatus; index: number; steps: Array<G.Step & { status: T.ProgressStatus }> }
processes: T.ProcessEvent[]
onContinue(): void
onLoadSolution(): void
level: G.Level & { status: T.ProgressStatus; index: number; steps: Array<G.Step & { status: T.ProgressStatus }> }
processes: T.ProcessEvent[]
onContinue(): void
onLoadSolution(): void
}

const Level = ({ level, onContinue, onLoadSolution, processes }: Props) => {
if (!level.steps) {
throw new Error('No Stage steps found')
}
if (!level.steps) {
throw new Error('No Stage steps found')
}

return (
<div style={styles.page}>
<div style={styles.header}>
<span>Learn</span>
</div>
<div style={styles.content}>
<h2 style={styles.title}>{level.title}</h2>
<Markdown>{level.content || ''}</Markdown>
</div>
return (
<div style={styles.page}>
<div style={styles.header}>
<span>Learn</span>
</div>
<div style={styles.content}>
<h2 style={styles.title}>{level.title}</h2>
<Markdown>{level.content || ''}</Markdown>
</div>

<div style={styles.tasks}>
<div style={styles.header}>Tasks</div>
<div style={styles.steps}>
{level.steps.map((step: (G.Step & { status: T.ProgressStatus }) | null, index: number) => {
if (!step) {
return null
}
return (
<Step
key={step.id}
order={index + 1}
status={step.status}
content={step.content}
onLoadSolution={onLoadSolution}
/>
)
})}
</div>
</div>
<div style={styles.tasks}>
<div style={styles.header}>Tasks</div>
<div style={styles.steps}>
{level.steps.map((step: (G.Step & { status: T.ProgressStatus }) | null, index: number) => {
if (!step) {
return null
}
return (
<Step
key={step.id}
order={index + 1}
status={step.status}
content={step.content}
onLoadSolution={onLoadSolution}
/>
)
})}
</div>
</div>

{processes.length > 0 && (
<div style={styles.processes}>
<ProcessEvents processes={processes} />
</div>
)}
{processes.length > 0 && (
<div style={styles.processes}>
<ProcessEvents processes={processes} />
</div>
)}

<div style={styles.footer}>
<span>
{typeof level.index === 'number' ? `${level.index + 1}. ` : ''}
{level.title}
</span>
<span>
{level.status === 'COMPLETE' && (
<Button type="primary" onClick={onContinue}>
Continue
</Button>
)}
</span>
</div>
</div>
)
<div style={styles.footer}>
<span>
{typeof level.index === 'number' ? `${level.index + 1}. ` : ''}
{level.title}
</span>
<span>
{level.status === 'COMPLETE' && (
<Button type="primary" onClick={onContinue}>
Continue
</Button>
)}
</span>
</div>
</div>
)
}

export default Level
Loading