diff --git a/src/core/validate.ts b/src/core/validate.ts index ed341b8..00bc3ab 100644 --- a/src/core/validate.ts +++ b/src/core/validate.ts @@ -191,14 +191,27 @@ export class Validate { * @returns Validation diagnostics with either a success message or errors. */ private async validateCveRecordSchema(cveRecord: JsonObject): Promise { - const validator = await this.cveRecordValidator; + let validator; + try { + validator = await this.cveRecordValidator; + + } catch (error) { + const errorMessage = error instanceof Error ? error.message : String(error); + + return Diagnostics.failSchemaValidation([ + `Error: ${errorMessage}`, + ]); + } + const isValid = validator(cveRecord); return isValid - ? Diagnostics.success() - : Diagnostics.failSchemaValidation(validator.errors ?? []); + ? Diagnostics.success() + : Diagnostics.failSchemaValidation(validator.errors ?? []); } + + /** * Validates a CVE record with CVE-specific metadata prechecks before running * AJV JSON schema validation. diff --git a/src/utils/fs.ts b/src/utils/fs.ts index 0b08083..9b629fe 100644 --- a/src/utils/fs.ts +++ b/src/utils/fs.ts @@ -28,7 +28,12 @@ export async function resolveExistingPath( } const checkedPaths = candidates.join(', '); - throw new Error(`Unable to find ${fileName}. Checked: ${checkedPaths}`); + throw new Error(`CVE Validation Library failed to validate CVE data. + + Try using npm to reinstall the library. If that does not work, file an issue in the repository: + https://github.com/CVEProject/cve-validation-library/issues/new + + Error: Unable to find ${fileName}. Checked: ${checkedPaths}`); } /**