From 3a352f72dac13f4ec2b547df65d8c007e656269f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Tue, 29 Aug 2023 10:57:13 +0100 Subject: [PATCH 1/6] test(exec): dont skip test --- tests/unit/ExecTest.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/unit/ExecTest.ts b/tests/unit/ExecTest.ts index 57bb2e8..1b33a66 100644 --- a/tests/unit/ExecTest.ts +++ b/tests/unit/ExecTest.ts @@ -24,10 +24,6 @@ export default class ExecTest { @Test() public async shouldBeAbleToExecuteACommandInTheVMAndGetTheStdout({ assert }: Context) { - if (Is.Windows()) { - return - } - const { stdout } = await Exec.command('ls') assert.isTrue(stdout.includes('README.md')) From 2e39e3daac69322078e434153dd27692f228b584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Tue, 29 Aug 2023 11:23:06 +0100 Subject: [PATCH 2/6] fix(exec): better error --- package-lock.json | 4 ++-- package.json | 2 +- src/exceptions/NodeCommandException.ts | 16 +++++++--------- src/helpers/Exec.ts | 18 ++++-------------- 4 files changed, 14 insertions(+), 26 deletions(-) diff --git a/package-lock.json b/package-lock.json index 359f3b9..c571cb2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/common", - "version": "4.9.0", + "version": "4.9.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@athenna/common", - "version": "4.9.0", + "version": "4.9.1", "license": "MIT", "dependencies": { "@fastify/formbody": "^7.4.0", diff --git a/package.json b/package.json index c7d3aca..9ec7e33 100644 --- a/package.json +++ b/package.json @@ -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 ", diff --git a/src/exceptions/NodeCommandException.ts b/src/exceptions/NodeCommandException.ts index 3f48a79..90c5b4d 100644 --- a/src/exceptions/NodeCommandException.ts +++ b/src/exceptions/NodeCommandException.ts @@ -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, diff --git a/src/helpers/Exec.ts b/src/helpers/Exec.ts index cafbccc..51a0a79 100644 --- a/src/helpers/Exec.ts +++ b/src/helpers/Exec.ts @@ -65,13 +65,8 @@ 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) @@ -79,13 +74,8 @@ export class Exec { 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) From 2d7396990e988314c2c3caf041742d346164760a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Tue, 29 Aug 2023 11:31:55 +0100 Subject: [PATCH 3/6] fix(exec): better error --- src/exceptions/NodeCommandException.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/exceptions/NodeCommandException.ts b/src/exceptions/NodeCommandException.ts index 90c5b4d..d678d1a 100644 --- a/src/exceptions/NodeCommandException.ts +++ b/src/exceptions/NodeCommandException.ts @@ -19,9 +19,9 @@ export class NodeCommandException extends Exception { delete error.stdout delete error.stderr - help = help.concat( - `\n\n Full command error:\n\n ${JSON.stringify(error)}`, - ) + help = help.concat(`\n\n Error name:\n\n ${error.name}}`) + help = help.concat(`\n\n Error message:\n\n ${error.message}}`) + help = help.concat(`\n\n Error stack:\n\n ${error.stack}}`) super({ help, From 9cd08a54f4dd964fd735f823072565e001ef3fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Tue, 29 Aug 2023 11:32:18 +0100 Subject: [PATCH 4/6] fix(exec): better error --- src/exceptions/NodeCommandException.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/exceptions/NodeCommandException.ts b/src/exceptions/NodeCommandException.ts index d678d1a..4c3effe 100644 --- a/src/exceptions/NodeCommandException.ts +++ b/src/exceptions/NodeCommandException.ts @@ -16,9 +16,6 @@ export class NodeCommandException extends Exception { help = help.concat(`Command stdout:\n\n ${error.stdout}`) help = help.concat(`\n\n Command stderr:\n\n ${error.stderr}`) - delete error.stdout - delete error.stderr - help = help.concat(`\n\n Error name:\n\n ${error.name}}`) help = help.concat(`\n\n Error message:\n\n ${error.message}}`) help = help.concat(`\n\n Error stack:\n\n ${error.stack}}`) From 7b209b781e088bbc26eeaf48b947929ff94afc67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Tue, 29 Aug 2023 13:08:55 +0100 Subject: [PATCH 5/6] fix(uuid): if token is undefined return false --- src/helpers/Uuid.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/helpers/Uuid.ts b/src/helpers/Uuid.ts index 7d97215..bbd3319 100644 --- a/src/helpers/Uuid.ts +++ b/src/helpers/Uuid.ts @@ -19,6 +19,10 @@ export class Uuid { token: string, options: { prefix?: string; ignorePrefix?: boolean } = {}, ): boolean { + if (!token) { + return false + } + options = Options.create(options, { ignorePrefix: true }) if (options.prefix) { From 7b3b5862a117184aebe9cc0430ab1e0cdce670d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Tue, 29 Aug 2023 13:13:38 +0100 Subject: [PATCH 6/6] fix(exec): better error help --- src/exceptions/NodeCommandException.ts | 4 +--- src/helpers/Exec.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/exceptions/NodeCommandException.ts b/src/exceptions/NodeCommandException.ts index 4c3effe..efe1128 100644 --- a/src/exceptions/NodeCommandException.ts +++ b/src/exceptions/NodeCommandException.ts @@ -16,9 +16,7 @@ export class NodeCommandException extends Exception { help = help.concat(`Command stdout:\n\n ${error.stdout}`) help = help.concat(`\n\n Command stderr:\n\n ${error.stderr}`) - help = help.concat(`\n\n Error name:\n\n ${error.name}}`) - help = help.concat(`\n\n Error message:\n\n ${error.message}}`) - help = help.concat(`\n\n Error stack:\n\n ${error.stack}}`) + help = help.concat(`\n\n ${error.stack}`) super({ help, diff --git a/src/helpers/Exec.ts b/src/helpers/Exec.ts index 51a0a79..5d44dca 100644 --- a/src/helpers/Exec.ts +++ b/src/helpers/Exec.ts @@ -54,15 +54,15 @@ export class Exec { ignoreErrors: false, }) - try { - const execOptions: ExecOptions = {} + const execOptions: ExecOptions = {} - if (Is.Windows() && Uuid.verify(process.env.WT_SESSION)) { - execOptions.shell = 'powershell' - } + if (Is.Windows() && Uuid.verify(process.env.WT_SESSION)) { + execOptions.shell = 'powershell' + } - debug('executing command: %s', command) + debug('executing command: %s', command) + try { const result = await exec(command, execOptions) if (!result.stdout) result.stdout = ''