File tree Expand file tree Collapse file tree 3 files changed +24
-9
lines changed Expand file tree Collapse file tree 3 files changed +24
-9
lines changed Original file line number Diff line number Diff line change @@ -17,15 +17,28 @@ SPDX-License-Identifier: Apache-2.0
1717Copyright (c) OWASP Foundation. All Rights Reserved.
1818*/
1919
20+ import { type Version } from '../spec'
21+
2022export class ValidationError extends Error {
2123 readonly details : any | undefined
2224
23- constructor ( message ? : string , details ?: any ) {
25+ constructor ( message : string , details ?: any ) {
2426 super ( message )
2527 this . details = details
2628 }
2729}
2830
29- export class NotImplementedError extends Error { }
31+ export class NotImplementedError extends Error {
32+ constructor ( version : Version ) {
33+ super ( `not implemented for CycloneDX version: ${ version } ` )
34+ }
35+ }
36+
37+ export class MissingOptionalDependencyError extends Error {
38+ readonly cause : any | undefined
3039
31- export class MissingOptionalDependencyError extends Error { }
40+ constructor ( message : string , cause ?: any ) {
41+ super ( message )
42+ this . cause = cause
43+ }
44+ }
Original file line number Diff line number Diff line change @@ -40,11 +40,12 @@ async function getAjv (): Promise<Ajv> {
4040 /* @ts -expect-error TS7016 */
4141 import ( 'ajv-formats-draft2019' )
4242 ] )
43- } catch {
43+ } catch ( err ) {
4444 throw new MissingOptionalDependencyError (
4545 'No JSON validator available.' +
4646 ' Please install all of the optional libraries:' +
47- ' ajv, ajv-formats, ajv-formats-draft2019'
47+ ' ajv, ajv-formats, ajv-formats-draft2019' ,
48+ err
4849 )
4950 }
5051
@@ -81,7 +82,7 @@ abstract class BaseJsonValidator extends BaseValidator {
8182 if ( this . #validator === undefined ) {
8283 const schemaFile = this . _getSchemaFile ( )
8384 if ( schemaFile === undefined ) {
84- throw new NotImplementedError ( `not implemented for version: ${ this . version } ` )
85+ throw new NotImplementedError ( this . version )
8586 }
8687 const [ ajv , schema ] = await Promise . all ( [
8788 getAjv ( ) ,
Original file line number Diff line number Diff line change @@ -32,11 +32,12 @@ async function getParser (): Promise<typeof parseXml> {
3232 let libxml
3333 try {
3434 libxml = await import ( 'libxmljs2' )
35- } catch {
35+ } catch ( err ) {
3636 throw new MissingOptionalDependencyError (
3737 'No XML validator available.' +
3838 ' Please install the optional libraries "libxmljs2".' +
39- ' Please make sure the system meets the requirements for node-gyp. https://github.com/TooTallNate/node-gyp#installation'
39+ ' Please make sure the system meets the requirements for node-gyp. https://github.com/TooTallNate/node-gyp#installation' ,
40+ err
4041 )
4142 }
4243 _parser = libxml . parseXml
@@ -60,7 +61,7 @@ export class XmlValidator extends BaseValidator {
6061 if ( undefined === this . #schema) {
6162 const file = this . #getSchemaFile( )
6263 if ( file === undefined ) {
63- throw new NotImplementedError ( `not implemented for version: ${ this . version } ` )
64+ throw new NotImplementedError ( this . version )
6465 }
6566 const [ parse , schema ] = await Promise . all ( [
6667 getParser ( ) ,
You can’t perform that action at this time.
0 commit comments