From 1c79bab8c6fd213dd7ff67905341c9085dfa9a0c Mon Sep 17 00:00:00 2001 From: Aleksandr Borovskii Date: Mon, 24 Jul 2023 15:39:29 +0200 Subject: [PATCH 1/9] feat(deploy): deploy repeater to new Docker org Closes #405 --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 8c4fcb53..85b25e98 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -182,7 +182,7 @@ jobs: uses: ./.github/workflows/composite/npm with: registry: 'https://npm.pkg.github.com' - scope: '@NeuraLegion' + scope: '@BrightSec' - run: npm publish --tag $TAG env: From bc8430793b0c78e4851b6c0aed81f4285c3d8983 Mon Sep 17 00:00:00 2001 From: Aleksandr Borovskii Date: Mon, 28 Oct 2024 08:25:21 +0100 Subject: [PATCH 2/9] feat(*): use unified error message template closes #600 --- src/Commands/Configure.ts | 8 +++++--- src/Commands/GetEntryPoints.ts | 8 +++++--- src/Commands/PollingScanStatus.ts | 12 +++++++----- src/Commands/RetestScan.ts | 8 +++++--- src/Commands/RunRepeater.ts | 10 ++++++---- src/Commands/RunScan.ts | 19 ++++++++++--------- src/Commands/StopScan.ts | 8 +++++--- src/Commands/UploadArchive.ts | 8 +++++--- src/Utils/ErrorMessageBuilder.ts | 22 ++++++++++++++++++++++ src/Utils/index.ts | 1 + 10 files changed, 71 insertions(+), 33 deletions(-) create mode 100644 src/Utils/ErrorMessageBuilder.ts diff --git a/src/Commands/Configure.ts b/src/Commands/Configure.ts index 8a817ef2..79b268ad 100644 --- a/src/Commands/Configure.ts +++ b/src/Commands/Configure.ts @@ -1,4 +1,4 @@ -import { logger } from '../Utils'; +import { ErrorMessageBuilder, logger } from '../Utils'; import { ConnectivityUrls, Platform, TestType, Options } from '../Wizard'; import container from '../container'; import { Arguments, Argv, CommandModule } from 'yargs'; @@ -98,8 +98,10 @@ export class Configure implements CommandModule { process.on('SIGTERM', stop).on('SIGINT', stop).on('SIGHUP', stop); await app.start({ ping: !!args.ping, traceroute: !!args.traceroute }); - } catch (e) { - logger.error(`Error during "configure": ${e.error || e.message}`); + } catch (error) { + logger.error( + ErrorMessageBuilder.buildMessage({ command: 'configure', error }) + ); process.exit(1); } } diff --git a/src/Commands/GetEntryPoints.ts b/src/Commands/GetEntryPoints.ts index 8336f728..91304c2d 100644 --- a/src/Commands/GetEntryPoints.ts +++ b/src/Commands/GetEntryPoints.ts @@ -1,5 +1,5 @@ import { EntryPoint, EntryPoints, RestProjectsOptions } from '../EntryPoint'; -import { logger } from '../Utils'; +import { ErrorMessageBuilder, logger } from '../Utils'; import { Arguments, Argv, CommandModule } from 'yargs'; import { container } from 'tsyringe'; @@ -86,8 +86,10 @@ export class GetEntryPoints implements CommandModule { } process.exitCode = 0; - } catch (e) { - logger.error(`Error during "entrypoints:list": ${e.error || e.message}`); + } catch (error) { + logger.error( + ErrorMessageBuilder.buildMessage({ command: 'entrypoints:list', error }) + ); process.exitCode = 1; } } diff --git a/src/Commands/PollingScanStatus.ts b/src/Commands/PollingScanStatus.ts index 2a1a0868..061be8ea 100644 --- a/src/Commands/PollingScanStatus.ts +++ b/src/Commands/PollingScanStatus.ts @@ -4,7 +4,7 @@ import { PollingFactory, RestScansOptions } from '../Scan'; -import { Helpers, logger } from '../Utils'; +import { ErrorMessageBuilder, Helpers, logger } from '../Utils'; import { Arguments, Argv, CommandModule } from 'yargs'; import { container } from 'tsyringe'; @@ -72,14 +72,16 @@ export class PollingScanStatus implements CommandModule { await polling.start(); process.exit(0); - } catch (e) { - if (e instanceof BreakpointException) { + } catch (error) { + if (error instanceof BreakpointException) { logger.error(`The breakpoint has been hit during polling.`); - logger.error(`Breakpoint: ${e.message}`); + logger.error(`Breakpoint: ${error.message}`); process.exit(50); } - logger.error(`Error during "scan:polling": ${e.error || e.message}`); + logger.error( + ErrorMessageBuilder.buildMessage({ command: 'scan:polling', error }) + ); process.exit(1); } } diff --git a/src/Commands/RetestScan.ts b/src/Commands/RetestScan.ts index deee8b2a..491c13fe 100644 --- a/src/Commands/RetestScan.ts +++ b/src/Commands/RetestScan.ts @@ -1,5 +1,5 @@ import { RestScansOptions, Scans } from '../Scan'; -import { logger } from '../Utils'; +import { ErrorMessageBuilder, logger } from '../Utils'; import { Arguments, Argv, CommandModule } from 'yargs'; import { container } from 'tsyringe'; @@ -42,8 +42,10 @@ export class RetestScan implements CommandModule { console.log(scanId); process.exit(0); - } catch (e) { - logger.error(`Error during "scan:retest": ${e.error || e.message}`); + } catch (error) { + logger.error( + ErrorMessageBuilder.buildMessage({ command: 'scan:retest', error }) + ); process.exit(1); } } diff --git a/src/Commands/RunRepeater.ts b/src/Commands/RunRepeater.ts index cfc4d6b2..d4556a61 100644 --- a/src/Commands/RunRepeater.ts +++ b/src/Commands/RunRepeater.ts @@ -1,5 +1,5 @@ import { Cert, RequestExecutorOptions } from '../RequestExecutor'; -import { Helpers, logger } from '../Utils'; +import { ErrorMessageBuilder, Helpers, logger } from '../Utils'; import container from '../container'; import { DefaultRepeaterServerOptions, RepeaterLauncher } from '../Repeater'; import { Arguments, Argv, CommandModule } from 'yargs'; @@ -254,9 +254,11 @@ export class RunRepeater implements CommandModule { ); await repeaterLauncher.run(args.id as string, args.run as boolean); - } catch (e) { - captureException(e); - logger.error(e); + } catch (error) { + captureException(error); + logger.error( + ErrorMessageBuilder.buildMessage({ command: 'repeater', error }) + ); await repeaterLauncher.close(); process.exitCode = 1; } diff --git a/src/Commands/RunScan.ts b/src/Commands/RunScan.ts index 245a8258..d269ccc4 100644 --- a/src/Commands/RunScan.ts +++ b/src/Commands/RunScan.ts @@ -7,10 +7,9 @@ import { Scans, ATTACK_PARAM_LOCATIONS_DEFAULT } from '../Scan'; -import { Helpers, logger } from '../Utils'; +import { ErrorMessageBuilder, Helpers, logger } from '../Utils'; import { Arguments, Argv, CommandModule } from 'yargs'; import { container } from 'tsyringe'; -import { isAxiosError } from 'axios'; import { EOL } from 'node:os'; export class RunScan implements CommandModule { @@ -25,7 +24,11 @@ export class RunScan implements CommandModule { if (!nonEmptyPatterns.length) { logger.error( - 'Error during "scan:run": please make sure that patterns contain at least one regexp.' + ErrorMessageBuilder.buildMessage({ + command: 'scan:run', + error: + 'please make sure that patterns contain at least one regexp' + }) ); process.exit(1); } @@ -213,12 +216,10 @@ export class RunScan implements CommandModule { } process.exit(0); - } catch (e) { - const errMessage = - isAxiosError(e) && typeof e.response?.data === 'string' - ? e.response.data - : e.error || e.message; - logger.error(`Error during "scan:run": ${errMessage}`); + } catch (error) { + logger.error( + ErrorMessageBuilder.buildMessage({ command: 'scan:run', error }) + ); process.exit(1); } } diff --git a/src/Commands/StopScan.ts b/src/Commands/StopScan.ts index 9cb5c53b..1e4a0962 100644 --- a/src/Commands/StopScan.ts +++ b/src/Commands/StopScan.ts @@ -1,5 +1,5 @@ import { RestScansOptions, Scans } from '../Scan'; -import { logger } from '../Utils'; +import { ErrorMessageBuilder, logger } from '../Utils'; import { Arguments, Argv, CommandModule } from 'yargs'; import { container } from 'tsyringe'; @@ -40,8 +40,10 @@ export class StopScan implements CommandModule { await scanManager.stop(args.scan as string); process.exit(0); - } catch (e) { - logger.error(`Error during "scan:stop": ${e.error || e.message}`); + } catch (error) { + logger.error( + ErrorMessageBuilder.buildMessage({ command: 'scan:stop', error }) + ); process.exit(1); } } diff --git a/src/Commands/UploadArchive.ts b/src/Commands/UploadArchive.ts index 68cda0de..7cf79b44 100644 --- a/src/Commands/UploadArchive.ts +++ b/src/Commands/UploadArchive.ts @@ -5,7 +5,7 @@ import { Spec, SpecType } from '../Archive'; -import { Helpers, logger } from '../Utils'; +import { ErrorMessageBuilder, Helpers, logger } from '../Utils'; import container from '../container'; import { Arguments, Argv, CommandModule } from 'yargs'; @@ -118,8 +118,10 @@ export class UploadArchive implements CommandModule { // eslint-disable-next-line no-console console.log(await archives.upload(spec)); process.exit(0); - } catch (e) { - logger.error(`Error during "archive:upload": ${e.message}`); + } catch (error) { + logger.error( + ErrorMessageBuilder.buildMessage({ command: 'archive:upload', error }) + ); process.exit(1); } } diff --git a/src/Utils/ErrorMessageBuilder.ts b/src/Utils/ErrorMessageBuilder.ts new file mode 100644 index 00000000..2d69336f --- /dev/null +++ b/src/Utils/ErrorMessageBuilder.ts @@ -0,0 +1,22 @@ +import { isAxiosError } from 'axios'; + +export class ErrorMessageBuilder { + public static buildMessage( + params: + | { error: unknown; message: string } + | { error: any; command: string } + ): string { + const message = ''; + 'message' in params ? params.message : `Error during "${params.command}"`; + + const errMessage = + typeof params.error === 'string' + ? params.error + : isAxiosError(params.error) && + typeof params.error.response?.data === 'string' + ? params.error.response.data + : params.error.error || params.error.message; + + return errMessage ? `${message}: ${errMessage}.` : `${message}.`; + } +} diff --git a/src/Utils/index.ts b/src/Utils/index.ts index 3fc0f10a..81e8d8d9 100644 --- a/src/Utils/index.ts +++ b/src/Utils/index.ts @@ -1,5 +1,6 @@ export * from './Backoff'; export * from './DefaultProxyFactory'; +export * from './ErrorMessageBuilder'; export * from './Helpers'; export * from './Logger'; export * from './ProxyFactory'; From 01b2e6a31031e7c9408543bb66b67b10e8b9882b Mon Sep 17 00:00:00 2001 From: Aleksandr Borovskii Date: Mon, 28 Oct 2024 13:34:18 +0100 Subject: [PATCH 3/9] feat(*): address PR comments closes #600 --- src/Commands/Configure.ts | 4 ++-- src/Commands/GetEntryPoints.ts | 7 ++++-- src/Commands/PollingScanStatus.ts | 7 ++++-- src/Commands/RetestScan.ts | 7 ++++-- src/Commands/RunRepeater.ts | 4 ++-- src/Commands/RunScan.ts | 6 +++--- src/Commands/StopScan.ts | 4 ++-- src/Commands/UploadArchive.ts | 7 ++++-- src/Utils/ErrorMessageBuilder.ts | 22 ------------------- src/Utils/ErrorMessageFactory.ts | 36 +++++++++++++++++++++++++++++++ src/Utils/index.ts | 2 +- 11 files changed, 66 insertions(+), 40 deletions(-) delete mode 100644 src/Utils/ErrorMessageBuilder.ts create mode 100644 src/Utils/ErrorMessageFactory.ts diff --git a/src/Commands/Configure.ts b/src/Commands/Configure.ts index 79b268ad..17ca0284 100644 --- a/src/Commands/Configure.ts +++ b/src/Commands/Configure.ts @@ -1,4 +1,4 @@ -import { ErrorMessageBuilder, logger } from '../Utils'; +import { ErrorMessageFactory, logger } from '../Utils'; import { ConnectivityUrls, Platform, TestType, Options } from '../Wizard'; import container from '../container'; import { Arguments, Argv, CommandModule } from 'yargs'; @@ -100,7 +100,7 @@ export class Configure implements CommandModule { await app.start({ ping: !!args.ping, traceroute: !!args.traceroute }); } catch (error) { logger.error( - ErrorMessageBuilder.buildMessage({ command: 'configure', error }) + ErrorMessageFactory.genericCommandError({ command: 'configure', error }) ); process.exit(1); } diff --git a/src/Commands/GetEntryPoints.ts b/src/Commands/GetEntryPoints.ts index 2a7fe594..60540497 100644 --- a/src/Commands/GetEntryPoints.ts +++ b/src/Commands/GetEntryPoints.ts @@ -1,5 +1,5 @@ import { EntryPoint, EntryPoints, RestProjectsOptions } from '../EntryPoint'; -import { ErrorMessageBuilder, logger } from '../Utils'; +import { ErrorMessageFactory, logger } from '../Utils'; import { Arguments, Argv, CommandModule } from 'yargs'; import { container } from 'tsyringe'; @@ -92,7 +92,10 @@ export class GetEntryPoints implements CommandModule { process.exitCode = 0; } catch (error) { logger.error( - ErrorMessageBuilder.buildMessage({ command: 'entrypoints:list', error }) + ErrorMessageFactory.genericCommandError({ + command: 'entrypoints:list', + error + }) ); process.exitCode = 1; } diff --git a/src/Commands/PollingScanStatus.ts b/src/Commands/PollingScanStatus.ts index 46f8fa18..c6748f6a 100644 --- a/src/Commands/PollingScanStatus.ts +++ b/src/Commands/PollingScanStatus.ts @@ -4,7 +4,7 @@ import { PollingFactory, RestScansOptions } from '../Scan'; -import { ErrorMessageBuilder, Helpers, logger } from '../Utils'; +import { ErrorMessageFactory, Helpers, logger } from '../Utils'; import { Arguments, Argv, CommandModule } from 'yargs'; import { container } from 'tsyringe'; @@ -81,7 +81,10 @@ export class PollingScanStatus implements CommandModule { } logger.error( - ErrorMessageBuilder.buildMessage({ command: 'scan:polling', error }) + ErrorMessageFactory.genericCommandError({ + command: 'scan:polling', + error + }) ); process.exit(1); } diff --git a/src/Commands/RetestScan.ts b/src/Commands/RetestScan.ts index bc07455e..fdce2b08 100644 --- a/src/Commands/RetestScan.ts +++ b/src/Commands/RetestScan.ts @@ -1,5 +1,5 @@ import { RestScansOptions, Scans } from '../Scan'; -import { ErrorMessageBuilder, logger } from '../Utils'; +import { ErrorMessageFactory, logger } from '../Utils'; import { Arguments, Argv, CommandModule } from 'yargs'; import { container } from 'tsyringe'; @@ -45,7 +45,10 @@ export class RetestScan implements CommandModule { process.exit(0); } catch (error) { logger.error( - ErrorMessageBuilder.buildMessage({ command: 'scan:retest', error }) + ErrorMessageFactory.genericCommandError({ + command: 'scan:retest', + error + }) ); process.exit(1); } diff --git a/src/Commands/RunRepeater.ts b/src/Commands/RunRepeater.ts index f33cf69e..a5fb61ba 100644 --- a/src/Commands/RunRepeater.ts +++ b/src/Commands/RunRepeater.ts @@ -1,5 +1,5 @@ import { Cert, RequestExecutorOptions } from '../RequestExecutor'; -import { ErrorMessageBuilder, Helpers, logger } from '../Utils'; +import { ErrorMessageFactory, Helpers, logger } from '../Utils'; import container from '../container'; import { DefaultRepeaterServerOptions, RepeaterLauncher } from '../Repeater'; import { Arguments, Argv, CommandModule } from 'yargs'; @@ -257,7 +257,7 @@ export class RunRepeater implements CommandModule { } catch (error) { captureException(error); logger.error( - ErrorMessageBuilder.buildMessage({ command: 'repeater', error }) + ErrorMessageFactory.genericCommandError({ command: 'repeater', error }) ); await repeaterLauncher.close(); process.exitCode = 1; diff --git a/src/Commands/RunScan.ts b/src/Commands/RunScan.ts index f423f17a..de103785 100644 --- a/src/Commands/RunScan.ts +++ b/src/Commands/RunScan.ts @@ -7,7 +7,7 @@ import { Scans, ATTACK_PARAM_LOCATIONS_DEFAULT } from '../Scan'; -import { ErrorMessageBuilder, Helpers, logger } from '../Utils'; +import { ErrorMessageFactory, Helpers, logger } from '../Utils'; import { Arguments, Argv, CommandModule } from 'yargs'; import { container } from 'tsyringe'; import { EOL } from 'node:os'; @@ -24,7 +24,7 @@ export class RunScan implements CommandModule { if (!nonEmptyPatterns.length) { logger.error( - ErrorMessageBuilder.buildMessage({ + ErrorMessageFactory.genericCommandError({ command: 'scan:run', error: 'please make sure that patterns contain at least one regexp' @@ -219,7 +219,7 @@ export class RunScan implements CommandModule { process.exit(0); } catch (error) { logger.error( - ErrorMessageBuilder.buildMessage({ command: 'scan:run', error }) + ErrorMessageFactory.genericCommandError({ command: 'scan:run', error }) ); process.exit(1); } diff --git a/src/Commands/StopScan.ts b/src/Commands/StopScan.ts index e8951fa5..673e5be3 100644 --- a/src/Commands/StopScan.ts +++ b/src/Commands/StopScan.ts @@ -1,5 +1,5 @@ import { RestScansOptions, Scans } from '../Scan'; -import { ErrorMessageBuilder, logger } from '../Utils'; +import { ErrorMessageFactory, logger } from '../Utils'; import { Arguments, Argv, CommandModule } from 'yargs'; import { container } from 'tsyringe'; @@ -43,7 +43,7 @@ export class StopScan implements CommandModule { process.exit(0); } catch (error) { logger.error( - ErrorMessageBuilder.buildMessage({ command: 'scan:stop', error }) + ErrorMessageFactory.genericCommandError({ command: 'scan:stop', error }) ); process.exit(1); } diff --git a/src/Commands/UploadArchive.ts b/src/Commands/UploadArchive.ts index eaf336e2..50b2a87f 100644 --- a/src/Commands/UploadArchive.ts +++ b/src/Commands/UploadArchive.ts @@ -5,7 +5,7 @@ import { Spec, SpecType } from '../Archive'; -import { ErrorMessageBuilder, Helpers, logger } from '../Utils'; +import { ErrorMessageFactory, Helpers, logger } from '../Utils'; import container from '../container'; import { Arguments, Argv, CommandModule } from 'yargs'; @@ -121,7 +121,10 @@ export class UploadArchive implements CommandModule { process.exit(0); } catch (error) { logger.error( - ErrorMessageBuilder.buildMessage({ command: 'archive:upload', error }) + ErrorMessageFactory.genericCommandError({ + command: 'archive:upload', + error + }) ); process.exit(1); } diff --git a/src/Utils/ErrorMessageBuilder.ts b/src/Utils/ErrorMessageBuilder.ts deleted file mode 100644 index 5ae944ed..00000000 --- a/src/Utils/ErrorMessageBuilder.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { isAxiosError } from 'axios'; - -export class ErrorMessageBuilder { - public static buildMessage( - params: - | { error: unknown; message: string } - | { error: any; command: string } - ): string { - const message = - 'message' in params ? params.message : `Error during "${params.command}"`; - - const errMessage = - typeof params.error === 'string' - ? params.error - : isAxiosError(params.error) && - typeof params.error.response?.data === 'string' - ? params.error.response.data - : params.error.error || params.error.message; - - return errMessage ? `${message}: ${errMessage}.` : `${message}.`; - } -} diff --git a/src/Utils/ErrorMessageFactory.ts b/src/Utils/ErrorMessageFactory.ts new file mode 100644 index 00000000..ec6290c3 --- /dev/null +++ b/src/Utils/ErrorMessageFactory.ts @@ -0,0 +1,36 @@ +import { isAxiosError } from 'axios'; + +type GenericCommandErrorParam = + | { command: string; error: any } + | { message: string; error: unknown }; + +export class ErrorMessageFactory { + public static genericCommandError(params: GenericCommandErrorParam): string { + const message = this.getMessageTitle(params); + const details = this.getMessageDetails(params); + + return details ? `${message}: ${details}.` : `${message}.`; + } + + private static getMessageTitle(params: GenericCommandErrorParam): string { + return 'message' in params + ? params.message + : `Error during "${params.command}"`; + } + + private static getMessageDetails( + params: GenericCommandErrorParam + ): string | null { + if (typeof params.error === 'string') { + return params.error; + } + if ( + isAxiosError(params.error) && + typeof params.error.response?.data === 'string' + ) { + params.error.response.data; + } + + return (params.error.error || params.error.message) ?? null; + } +} diff --git a/src/Utils/index.ts b/src/Utils/index.ts index 81e8d8d9..fb970383 100644 --- a/src/Utils/index.ts +++ b/src/Utils/index.ts @@ -1,6 +1,6 @@ export * from './Backoff'; export * from './DefaultProxyFactory'; -export * from './ErrorMessageBuilder'; +export * from './ErrorMessageFactory'; export * from './Helpers'; export * from './Logger'; export * from './ProxyFactory'; From 1306b25321b936272814fc9a1dd3c2d648ce0d06 Mon Sep 17 00:00:00 2001 From: Aleksandr Borovskii Date: Mon, 28 Oct 2024 13:36:15 +0100 Subject: [PATCH 4/9] feat(*): address PR comments closes #600 --- src/Commands/Configure.ts | 2 +- src/Commands/GetEntryPoints.ts | 4 ++-- src/Commands/PollingScanStatus.ts | 4 ++-- src/Commands/RetestScan.ts | 4 ++-- src/Commands/RunRepeater.ts | 2 +- src/Commands/RunScan.ts | 2 +- src/Commands/StopScan.ts | 2 +- src/Commands/UploadArchive.ts | 4 ++-- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Commands/Configure.ts b/src/Commands/Configure.ts index 17ca0284..7dc94205 100644 --- a/src/Commands/Configure.ts +++ b/src/Commands/Configure.ts @@ -100,7 +100,7 @@ export class Configure implements CommandModule { await app.start({ ping: !!args.ping, traceroute: !!args.traceroute }); } catch (error) { logger.error( - ErrorMessageFactory.genericCommandError({ command: 'configure', error }) + ErrorMessageFactory.genericCommandError({ error, command: 'configure' }) ); process.exit(1); } diff --git a/src/Commands/GetEntryPoints.ts b/src/Commands/GetEntryPoints.ts index 60540497..7548b935 100644 --- a/src/Commands/GetEntryPoints.ts +++ b/src/Commands/GetEntryPoints.ts @@ -93,8 +93,8 @@ export class GetEntryPoints implements CommandModule { } catch (error) { logger.error( ErrorMessageFactory.genericCommandError({ - command: 'entrypoints:list', - error + error, + command: 'entrypoints:list' }) ); process.exitCode = 1; diff --git a/src/Commands/PollingScanStatus.ts b/src/Commands/PollingScanStatus.ts index c6748f6a..d8ddd72d 100644 --- a/src/Commands/PollingScanStatus.ts +++ b/src/Commands/PollingScanStatus.ts @@ -82,8 +82,8 @@ export class PollingScanStatus implements CommandModule { logger.error( ErrorMessageFactory.genericCommandError({ - command: 'scan:polling', - error + error, + command: 'scan:polling' }) ); process.exit(1); diff --git a/src/Commands/RetestScan.ts b/src/Commands/RetestScan.ts index fdce2b08..c759a7e4 100644 --- a/src/Commands/RetestScan.ts +++ b/src/Commands/RetestScan.ts @@ -46,8 +46,8 @@ export class RetestScan implements CommandModule { } catch (error) { logger.error( ErrorMessageFactory.genericCommandError({ - command: 'scan:retest', - error + error, + command: 'scan:retest' }) ); process.exit(1); diff --git a/src/Commands/RunRepeater.ts b/src/Commands/RunRepeater.ts index a5fb61ba..6c7aaaf7 100644 --- a/src/Commands/RunRepeater.ts +++ b/src/Commands/RunRepeater.ts @@ -257,7 +257,7 @@ export class RunRepeater implements CommandModule { } catch (error) { captureException(error); logger.error( - ErrorMessageFactory.genericCommandError({ command: 'repeater', error }) + ErrorMessageFactory.genericCommandError({ error, command: 'repeater' }) ); await repeaterLauncher.close(); process.exitCode = 1; diff --git a/src/Commands/RunScan.ts b/src/Commands/RunScan.ts index de103785..f6880c56 100644 --- a/src/Commands/RunScan.ts +++ b/src/Commands/RunScan.ts @@ -219,7 +219,7 @@ export class RunScan implements CommandModule { process.exit(0); } catch (error) { logger.error( - ErrorMessageFactory.genericCommandError({ command: 'scan:run', error }) + ErrorMessageFactory.genericCommandError({ error, command: 'scan:run' }) ); process.exit(1); } diff --git a/src/Commands/StopScan.ts b/src/Commands/StopScan.ts index 673e5be3..16cee97b 100644 --- a/src/Commands/StopScan.ts +++ b/src/Commands/StopScan.ts @@ -43,7 +43,7 @@ export class StopScan implements CommandModule { process.exit(0); } catch (error) { logger.error( - ErrorMessageFactory.genericCommandError({ command: 'scan:stop', error }) + ErrorMessageFactory.genericCommandError({ error, command: 'scan:stop' }) ); process.exit(1); } diff --git a/src/Commands/UploadArchive.ts b/src/Commands/UploadArchive.ts index 50b2a87f..48528c9c 100644 --- a/src/Commands/UploadArchive.ts +++ b/src/Commands/UploadArchive.ts @@ -122,8 +122,8 @@ export class UploadArchive implements CommandModule { } catch (error) { logger.error( ErrorMessageFactory.genericCommandError({ - command: 'archive:upload', - error + error, + command: 'archive:upload' }) ); process.exit(1); From ce4b7dfe63892b9660dff6bf78db9726bff6d118 Mon Sep 17 00:00:00 2001 From: Alexander Borovsky Date: Tue, 29 Oct 2024 11:35:23 +0100 Subject: [PATCH 5/9] Update src/Utils/ErrorMessageFactory.ts Co-authored-by: Artem Derevnjuk --- src/Utils/ErrorMessageFactory.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Utils/ErrorMessageFactory.ts b/src/Utils/ErrorMessageFactory.ts index ec6290c3..0fba98f4 100644 --- a/src/Utils/ErrorMessageFactory.ts +++ b/src/Utils/ErrorMessageFactory.ts @@ -9,7 +9,14 @@ export class ErrorMessageFactory { const message = this.getMessageTitle(params); const details = this.getMessageDetails(params); - return details ? `${message}: ${details}.` : `${message}.`; + return this.formatFinalMessage(message, details); + } + + private static formatFinalMessage(baseMessage: string, errorDetails?: string): string { + return errorDetails + ? `${baseMessage}: ${errorDetails}.` + : `${baseMessage}.`; + } } private static getMessageTitle(params: GenericCommandErrorParam): string { From 7cc99d04d5d6430b76bbcf7132cc752a3a499886 Mon Sep 17 00:00:00 2001 From: Alexander Borovsky Date: Tue, 29 Oct 2024 11:35:29 +0100 Subject: [PATCH 6/9] Update src/Utils/ErrorMessageFactory.ts Co-authored-by: Artem Derevnjuk --- src/Utils/ErrorMessageFactory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utils/ErrorMessageFactory.ts b/src/Utils/ErrorMessageFactory.ts index 0fba98f4..6e21b65c 100644 --- a/src/Utils/ErrorMessageFactory.ts +++ b/src/Utils/ErrorMessageFactory.ts @@ -25,7 +25,7 @@ export class ErrorMessageFactory { : `Error during "${params.command}"`; } - private static getMessageDetails( + private static extractErrorDetails( params: GenericCommandErrorParam ): string | null { if (typeof params.error === 'string') { From 0e143c5c93d3857eb96cb89c5473aa845033d011 Mon Sep 17 00:00:00 2001 From: Alexander Borovsky Date: Tue, 29 Oct 2024 11:35:35 +0100 Subject: [PATCH 7/9] Update src/Utils/ErrorMessageFactory.ts Co-authored-by: Artem Derevnjuk --- src/Utils/ErrorMessageFactory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utils/ErrorMessageFactory.ts b/src/Utils/ErrorMessageFactory.ts index 6e21b65c..325d5ac8 100644 --- a/src/Utils/ErrorMessageFactory.ts +++ b/src/Utils/ErrorMessageFactory.ts @@ -1,6 +1,6 @@ import { isAxiosError } from 'axios'; -type GenericCommandErrorParam = +type GenericCommandErrorParams = | { command: string; error: any } | { message: string; error: unknown }; From 0700a37b245a3e8dce06fa04c173668fe69bddcc Mon Sep 17 00:00:00 2001 From: Aleksandr Borovskii Date: Tue, 29 Oct 2024 11:36:46 +0100 Subject: [PATCH 8/9] feat(*): address PR comments closes #600 --- src/Utils/ErrorMessageFactory.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Utils/ErrorMessageFactory.ts b/src/Utils/ErrorMessageFactory.ts index 325d5ac8..9a4fc59d 100644 --- a/src/Utils/ErrorMessageFactory.ts +++ b/src/Utils/ErrorMessageFactory.ts @@ -5,28 +5,30 @@ type GenericCommandErrorParams = | { message: string; error: unknown }; export class ErrorMessageFactory { - public static genericCommandError(params: GenericCommandErrorParam): string { + public static genericCommandError(params: GenericCommandErrorParams): string { const message = this.getMessageTitle(params); - const details = this.getMessageDetails(params); + const details = this.extractErrorDetails(params); return this.formatFinalMessage(message, details); } - - private static formatFinalMessage(baseMessage: string, errorDetails?: string): string { - return errorDetails + + private static formatFinalMessage( + baseMessage: string, + errorDetails?: string + ): string { + return errorDetails ? `${baseMessage}: ${errorDetails}.` : `${baseMessage}.`; } - } - private static getMessageTitle(params: GenericCommandErrorParam): string { + private static getMessageTitle(params: GenericCommandErrorParams): string { return 'message' in params ? params.message : `Error during "${params.command}"`; } private static extractErrorDetails( - params: GenericCommandErrorParam + params: GenericCommandErrorParams ): string | null { if (typeof params.error === 'string') { return params.error; From c6c0f261a804995ac1d6689b43dae492cf3bb7e0 Mon Sep 17 00:00:00 2001 From: Aleksandr Borovskii Date: Tue, 29 Oct 2024 11:37:09 +0100 Subject: [PATCH 9/9] feat(*): address PR comments closes #600 --- src/Utils/ErrorMessageFactory.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Utils/ErrorMessageFactory.ts b/src/Utils/ErrorMessageFactory.ts index 9a4fc59d..26e9ffac 100644 --- a/src/Utils/ErrorMessageFactory.ts +++ b/src/Utils/ErrorMessageFactory.ts @@ -6,7 +6,7 @@ type GenericCommandErrorParams = export class ErrorMessageFactory { public static genericCommandError(params: GenericCommandErrorParams): string { - const message = this.getMessageTitle(params); + const message = this.getTitle(params); const details = this.extractErrorDetails(params); return this.formatFinalMessage(message, details); @@ -21,7 +21,7 @@ export class ErrorMessageFactory { : `${baseMessage}.`; } - private static getMessageTitle(params: GenericCommandErrorParams): string { + private static getTitle(params: GenericCommandErrorParams): string { return 'message' in params ? params.message : `Error during "${params.command}"`;