Skip to content

Commit

Permalink
fix(exec): better error
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Aug 29, 2023
1 parent 3a352f7 commit 2e39e3d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/common",
"version": "4.9.0",
"version": "4.9.1",
"description": "The Athenna common helpers to use in any Node.js ESM project.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down
16 changes: 7 additions & 9 deletions src/exceptions/NodeCommandException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ export class NodeCommandException extends Exception {
public constructor(command: string, error: any) {
let help = ''

if (error.stdout) {
help = help.concat(`Command stdout:\n\n${error.stdout}`)
}
help = help.concat(`Command stdout:\n\n ${error.stdout}`)
help = help.concat(`\n\n Command stderr:\n\n ${error.stderr}`)

if (error.stderr) {
help = help.concat(`Command stderr:\n\n${error.stderr}`)
}
delete error.stdout
delete error.stderr

if (!error.stdout && !error.stdout) {
help = `Command error:\n\n${JSON.stringify(error)}`
}
help = help.concat(
`\n\n Full command error:\n\n ${JSON.stringify(error)}`,
)

super({
help,
Expand Down
18 changes: 4 additions & 14 deletions src/helpers/Exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,17 @@ export class Exec {

const result = await exec(command, execOptions)

if (!result.stdout) {
result.stdout = ''
}

if (!result.stderr) {
result.stderr = ''
}
if (!result.stdout) result.stdout = ''
if (!result.stderr) result.stderr = ''

debug('command executed successfully')
debug('command stdout: %s', result.stdout)
debug('command stderr: %s', result.stderr)

return result
} catch (error) {
if (!error.stdout) {
error.stdout = ''
}

if (!error.stderr) {
error.stderr = ''
}
if (!error.stdout) error.stdout = ''
if (!error.stderr) error.stderr = ''

debug('command has failed')
debug('command stdout: %s', error.stdout)
Expand Down

0 comments on commit 2e39e3d

Please sign in to comment.