File tree 3 files changed +24
-9
lines changed
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
17
17
Copyright (c) OWASP Foundation. All Rights Reserved.
18
18
*/
19
19
20
+ import { type Version } from '../spec'
21
+
20
22
export class ValidationError extends Error {
21
23
readonly details : any | undefined
22
24
23
- constructor ( message ? : string , details ?: any ) {
25
+ constructor ( message : string , details ?: any ) {
24
26
super ( message )
25
27
this . details = details
26
28
}
27
29
}
28
30
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
30
39
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> {
40
40
/* @ts -expect-error TS7016 */
41
41
import ( 'ajv-formats-draft2019' )
42
42
] )
43
- } catch {
43
+ } catch ( err ) {
44
44
throw new MissingOptionalDependencyError (
45
45
'No JSON validator available.' +
46
46
' Please install all of the optional libraries:' +
47
- ' ajv, ajv-formats, ajv-formats-draft2019'
47
+ ' ajv, ajv-formats, ajv-formats-draft2019' ,
48
+ err
48
49
)
49
50
}
50
51
@@ -81,7 +82,7 @@ abstract class BaseJsonValidator extends BaseValidator {
81
82
if ( this . #validator === undefined ) {
82
83
const schemaFile = this . _getSchemaFile ( )
83
84
if ( schemaFile === undefined ) {
84
- throw new NotImplementedError ( `not implemented for version: ${ this . version } ` )
85
+ throw new NotImplementedError ( this . version )
85
86
}
86
87
const [ ajv , schema ] = await Promise . all ( [
87
88
getAjv ( ) ,
Original file line number Diff line number Diff line change @@ -32,11 +32,12 @@ async function getParser (): Promise<typeof parseXml> {
32
32
let libxml
33
33
try {
34
34
libxml = await import ( 'libxmljs2' )
35
- } catch {
35
+ } catch ( err ) {
36
36
throw new MissingOptionalDependencyError (
37
37
'No XML validator available.' +
38
38
' 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
40
41
)
41
42
}
42
43
_parser = libxml . parseXml
@@ -60,7 +61,7 @@ export class XmlValidator extends BaseValidator {
60
61
if ( undefined === this . #schema) {
61
62
const file = this . #getSchemaFile( )
62
63
if ( file === undefined ) {
63
- throw new NotImplementedError ( `not implemented for version: ${ this . version } ` )
64
+ throw new NotImplementedError ( this . version )
64
65
}
65
66
const [ parse , schema ] = await Promise . all ( [
66
67
getParser ( ) ,
You can’t perform that action at this time.
0 commit comments