From 14fe00da1a4591b5ddfce0beef1496aaa4d45923 Mon Sep 17 00:00:00 2001 From: Will Osborne Date: Mon, 18 Nov 2024 11:14:59 +0000 Subject: [PATCH 1/3] Fix CLI errors from module split system --- cli/src/index.ts | 2 +- shared/package.json | 4 ++-- shared/src/commands/generate/schema-directory.ts | 2 +- shared/src/commands/validate/validate.ts | 2 +- shared/src/consts.ts | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/src/index.ts b/cli/src/index.ts index 2e9e3f39..ddd79651 100644 --- a/cli/src/index.ts +++ b/cli/src/index.ts @@ -64,7 +64,7 @@ program .option(OUTPUT_OPTION, 'Path location at which to output the generated file.') .option(VERBOSE_OPTION, 'Enable verbose logging.', false) .action(async (options) => { - const outcome = await validate(options.instantiation, options.pattern, options.metaSchemasLocation, options.verbose); + const outcome = await validate(options.instantiation, options.pattern, options.schemaDirectory, options.verbose); const content = getFormattedOutput(outcome, options.format, options.instantiation, options.pattern); writeOutputFile(options.output, content); exitBasedOffOfValidationOutcome(outcome, options.strict); diff --git a/shared/package.json b/shared/package.json index 75d8816f..f2eea80c 100644 --- a/shared/package.json +++ b/shared/package.json @@ -15,8 +15,8 @@ "test": "jest --verbose", "lint": "eslint src --config ./.eslintrc.json", "lint-fix": "eslint src -- --fix", - "copy-calm-schema": "copyfiles ../calm/draft/2024-04/meta/* dist/calm/", - "copy-spectral-rules": "copyfiles ../spectral/**/* dist/spectral/", + "copy-calm-schema": "copyfiles \"../calm/draft/2024-04/meta/*\" dist/calm/", + "copy-spectral-rules": "copyfiles \"../spectral/**/*\" dist/spectral/", "copy-calm-schema-old": "mkdir -p dist/calm && cp -r ../calm/draft/2024-04/meta dist/calm/", "dependency-check": "dependency-check --project 'calm-shared' --scan . --out ./dependency-check-report --format ALL --suppression ../.github/node-cve-ignore-list.xml" }, diff --git a/shared/src/commands/generate/schema-directory.ts b/shared/src/commands/generate/schema-directory.ts index 5172bf7a..d4dbf61a 100644 --- a/shared/src/commands/generate/schema-directory.ts +++ b/shared/src/commands/generate/schema-directory.ts @@ -50,7 +50,7 @@ export class SchemaDirectory { this.logger.info(`Loaded ${this.schemas.size} schemas.`); } catch (err) { if (err.code === 'ENOENT') { - this.logger.error('Schema Path not found!'); + this.logger.error('Schema Path not found: ' + dir); } else { this.logger.error(err); } diff --git a/shared/src/commands/validate/validate.ts b/shared/src/commands/validate/validate.ts index 40d066d6..1236d370 100644 --- a/shared/src/commands/validate/validate.ts +++ b/shared/src/commands/validate/validate.ts @@ -331,7 +331,7 @@ export async function validate( return new ValidationOutcome(jsonSchemaValidations, spectralResult.spectralIssues, errors, warnings); } catch (error) { - logger.error(`An error occured: ${error}`); + logger.error('An error occured:', error); process.exit(1); } } diff --git a/shared/src/consts.ts b/shared/src/consts.ts index 6a60eb5a..1cd9f1da 100644 --- a/shared/src/consts.ts +++ b/shared/src/consts.ts @@ -1,2 +1,2 @@ -export const CALM_META_SCHEMA_DIRECTORY = __dirname + '/calm/meta'; +export const CALM_META_SCHEMA_DIRECTORY = __dirname + '/calm/draft'; export const CALM_SPECTRAL_RULES_DIRECTORY = __dirname + '/spectral'; \ No newline at end of file From 43a6decf0e8a8f831939a57c9040a952b30e86de Mon Sep 17 00:00:00 2001 From: Will Osborne Date: Mon, 18 Nov 2024 11:15:22 +0000 Subject: [PATCH 2/3] Correctly log stack trace when errors are logged --- shared/src/commands/helper.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/shared/src/commands/helper.ts b/shared/src/commands/helper.ts index 42147fec..de59197d 100644 --- a/shared/src/commands/helper.ts +++ b/shared/src/commands/helper.ts @@ -7,6 +7,15 @@ export function initLogger(debug: boolean): winston.Logger { new winston.transports.Console() ], level: level, - format: winston.format.cli(), + format: winston.format.combine( + winston.format.cli(), + winston.format.errors({ stack: true }), + winston.format.printf(({ level, message, stack }) => { + if (stack) { + return `${level}: ${message} - ${stack}`; + } + return `${level}: ${message}`; + }), + ) }); } \ No newline at end of file From 462a146299e8f9f85150247e43073b376a0781b5 Mon Sep 17 00:00:00 2001 From: Will Osborne Date: Mon, 18 Nov 2024 14:36:22 +0000 Subject: [PATCH 3/3] Suggestion from PR --- shared/src/commands/generate/schema-directory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/src/commands/generate/schema-directory.ts b/shared/src/commands/generate/schema-directory.ts index d4dbf61a..6956ec08 100644 --- a/shared/src/commands/generate/schema-directory.ts +++ b/shared/src/commands/generate/schema-directory.ts @@ -50,7 +50,7 @@ export class SchemaDirectory { this.logger.info(`Loaded ${this.schemas.size} schemas.`); } catch (err) { if (err.code === 'ENOENT') { - this.logger.error('Schema Path not found: ' + dir); + this.logger.error('Schema Path not found: ', dir, ', error: ', err); } else { this.logger.error(err); }