Skip to content

capture error on command failure #563

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
Jan 9, 2022
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
1 change: 0 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ cd web-app
yarn build
cd ..

# For Windows build: switch the next 2 lines
echo "Bundling webapp..."
if [[ "$OSTYPE" == "msys" ]]; then
# linux subsystem on windows selected
Expand Down
6 changes: 5 additions & 1 deletion src/services/hooks/utils/runCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ const runCommands = async (commands: string[] = []): Promise<void> => {
title: command,
description: 'Running process...',
}
logger(`Command: ${command}`)
send({ type: 'COMMAND_START', payload: { process: { ...process, status: 'RUNNING' } } })
let result: { stdout: string; stderr: string }
try {
result = await exec({ command })
logger(`Command output: ${JSON.stringify(result)}`)
if (result.stderr) {
throw new Error(result.stderr)
}
logger(`Command output: ${result.stdout}`)
} catch (error: any) {
logger(`Command failed: ${error.message}`)
send({ type: '', payload: { process: { ...process, status: 'FAIL' } } })
Expand Down
15 changes: 12 additions & 3 deletions src/services/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,40 @@ interface ExecParams {

// correct paths to be from workspace root rather than extension folder
const getWorkspacePath = (...paths: string[]) => {
return join(WORKSPACE_ROOT, ...paths)
const workspacePath = join(WORKSPACE_ROOT, ...paths)
logger(`Workspace path: ${workspacePath}`)
return workspacePath
}

export const exec = (params: ExecParams): Promise<{ stdout: string; stderr: string }> | never => {
const cwd = join(WORKSPACE_ROOT, params.dir || '')
logger(`Calling command: ${params.command}`)
return asyncExec(params.command, { cwd })
}

export const exists = (...paths: string[]): boolean | never => {
return fs.existsSync(getWorkspacePath(...paths))
const filePath = getWorkspacePath(...paths)
logger(`Check file exists: ${filePath}`)
return fs.existsSync(filePath)
}

export const removeFile = (...paths: string[]) => {
return asyncRemoveFile(getWorkspacePath(...paths))
const filePath = getWorkspacePath(...paths)
logger(`Removing file: ${filePath}`)
return asyncRemoveFile(filePath)
}

export const readFile = (...paths: string[]): Promise<string | void> => {
const filePath = getWorkspacePath(...paths)
logger(`Reading file: ${filePath}`)
return asyncReadFile(getWorkspacePath(...paths), 'utf8').catch((err) => {
logger(`Failed to read from ${filePath}: ${err.message}`)
})
}

export const writeFile = (data: any, ...paths: string[]): Promise<void> => {
const filePath = getWorkspacePath(...paths)
logger(`Writing file: ${filePath}`)
return asyncWriteFile(filePath, data).catch((err) => {
logger(`Failed to write to ${filePath}: ${err.message}`)
})
Expand Down