diff --git a/packages/apidom-reference/src/dereference/index.ts b/packages/apidom-reference/src/dereference/index.ts index 47d51baf13..960ea7968c 100644 --- a/packages/apidom-reference/src/dereference/index.ts +++ b/packages/apidom-reference/src/dereference/index.ts @@ -57,7 +57,7 @@ export const dereferenceApiDOM = async ( // unwrap the element from ParseResult assuming first element is the actual result return surrogateWrapping ? result.get(0) : result; } catch (error: any) { - throw new DereferenceError(`Error while dereferencing file "${file.uri}"`, error); + throw new DereferenceError(`Error while dereferencing file "${file.uri}"`, { cause: error }); } }; diff --git a/packages/apidom-reference/src/parse/index.ts b/packages/apidom-reference/src/parse/index.ts index 5f42ed8671..a913127ea1 100644 --- a/packages/apidom-reference/src/parse/index.ts +++ b/packages/apidom-reference/src/parse/index.ts @@ -36,7 +36,7 @@ const parseFile = async (file: IFile, options: IReferenceOptions): Promise = stampit(Parser, { const parserOpts = pick(['sourceMap', 'syntacticAnalysis', 'refractorOpts'], this); return await parse(source, parserOpts); } catch (error: any) { - throw new ParserError(`Error parsing "${file.uri}"`, error); + throw new ParserError(`Error parsing "${file.uri}"`, { cause: error }); } }, }, diff --git a/packages/apidom-reference/src/parse/parsers/api-design-systems-yaml/index.ts b/packages/apidom-reference/src/parse/parsers/api-design-systems-yaml/index.ts index 98329128f3..4bbf8769bf 100644 --- a/packages/apidom-reference/src/parse/parsers/api-design-systems-yaml/index.ts +++ b/packages/apidom-reference/src/parse/parsers/api-design-systems-yaml/index.ts @@ -37,7 +37,7 @@ const ApiDesignSystemsYamlParser: stampit.Stamp = stampit(Parser, { const parserOpts = pick(['sourceMap', 'refractorOpts'], this); return await parse(source, parserOpts); } catch (error: any) { - throw new ParserError(`Error parsing "${file.uri}"`, error); + throw new ParserError(`Error parsing "${file.uri}"`, { cause: error }); } }, }, diff --git a/packages/apidom-reference/src/parse/parsers/asyncapi-json-2/index.ts b/packages/apidom-reference/src/parse/parsers/asyncapi-json-2/index.ts index 1f150354af..9311f644fd 100644 --- a/packages/apidom-reference/src/parse/parsers/asyncapi-json-2/index.ts +++ b/packages/apidom-reference/src/parse/parsers/asyncapi-json-2/index.ts @@ -33,7 +33,7 @@ const AsyncApiJson2Parser: stampit.Stamp = stampit(Parser, { const parserOpts = pick(['sourceMap', 'syntacticAnalysis', 'refractorOpts'], this); return await parse(source, parserOpts); } catch (error: any) { - throw new ParserError(`Error parsing "${file.uri}"`, error); + throw new ParserError(`Error parsing "${file.uri}"`, { cause: error }); } }, }, diff --git a/packages/apidom-reference/src/parse/parsers/asyncapi-yaml-2/index.ts b/packages/apidom-reference/src/parse/parsers/asyncapi-yaml-2/index.ts index e3495c24ee..97135a2fe7 100644 --- a/packages/apidom-reference/src/parse/parsers/asyncapi-yaml-2/index.ts +++ b/packages/apidom-reference/src/parse/parsers/asyncapi-yaml-2/index.ts @@ -33,7 +33,7 @@ const AsyncApiYaml2Parser: stampit.Stamp = stampit(Parser, { const parserOpts = pick(['sourceMap', 'refractorOpts'], this); return await parse(source, parserOpts); } catch (error: any) { - throw new ParserError(`Error parsing "${file.uri}"`, error); + throw new ParserError(`Error parsing "${file.uri}"`, { cause: error }); } }, }, diff --git a/packages/apidom-reference/src/parse/parsers/binary/index-browser.ts b/packages/apidom-reference/src/parse/parsers/binary/index-browser.ts index 108b3d35e8..8d72f031cb 100644 --- a/packages/apidom-reference/src/parse/parsers/binary/index-browser.ts +++ b/packages/apidom-reference/src/parse/parsers/binary/index-browser.ts @@ -46,7 +46,7 @@ const BinaryParser: stampit.Stamp = stampit(Parser, { return parseResultElement; } catch (error: any) { - throw new ParserError(`Error parsing "${file.uri}"`, error); + throw new ParserError(`Error parsing "${file.uri}"`, { cause: error }); } }, }, diff --git a/packages/apidom-reference/src/parse/parsers/binary/index-node.ts b/packages/apidom-reference/src/parse/parsers/binary/index-node.ts index 7e63471de3..e2d1f34bec 100644 --- a/packages/apidom-reference/src/parse/parsers/binary/index-node.ts +++ b/packages/apidom-reference/src/parse/parsers/binary/index-node.ts @@ -43,7 +43,7 @@ const BinaryParser: stampit.Stamp = stampit(Parser, { return parseResultElement; } catch (error: any) { - throw new ParserError(`Error parsing "${file.uri}"`, error); + throw new ParserError(`Error parsing "${file.uri}"`, { cause: error }); } }, }, diff --git a/packages/apidom-reference/src/parse/parsers/json/index.ts b/packages/apidom-reference/src/parse/parsers/json/index.ts index d7c2cdc31b..8b66acb371 100644 --- a/packages/apidom-reference/src/parse/parsers/json/index.ts +++ b/packages/apidom-reference/src/parse/parsers/json/index.ts @@ -33,7 +33,7 @@ const JsonParser: stampit.Stamp = stampit(Parser, { const parserOpts = pick(['sourceMap', 'syntacticAnalysis'], this); return await parse(source, parserOpts); } catch (error: any) { - throw new ParserError(`Error parsing "${file.uri}"`, error); + throw new ParserError(`Error parsing "${file.uri}"`, { cause: error }); } }, }, diff --git a/packages/apidom-reference/src/parse/parsers/openapi-json-3-0/index.ts b/packages/apidom-reference/src/parse/parsers/openapi-json-3-0/index.ts index 45635068e8..1e22ad5c8e 100644 --- a/packages/apidom-reference/src/parse/parsers/openapi-json-3-0/index.ts +++ b/packages/apidom-reference/src/parse/parsers/openapi-json-3-0/index.ts @@ -34,7 +34,7 @@ const OpenApiJson3_0Parser: stampit.Stamp = stampit(Parser, { const parserOpts = pick(['sourceMap', 'syntacticAnalysis', 'refractorOpts'], this); return await parse(source, parserOpts); } catch (error: any) { - throw new ParserError(`Error parsing "${file.uri}"`, error); + throw new ParserError(`Error parsing "${file.uri}"`, { cause: error }); } }, }, diff --git a/packages/apidom-reference/src/parse/parsers/openapi-json-3-1/index.ts b/packages/apidom-reference/src/parse/parsers/openapi-json-3-1/index.ts index 03ec0bef2f..e416f10375 100644 --- a/packages/apidom-reference/src/parse/parsers/openapi-json-3-1/index.ts +++ b/packages/apidom-reference/src/parse/parsers/openapi-json-3-1/index.ts @@ -34,7 +34,7 @@ const OpenApiJson3_1Parser: stampit.Stamp = stampit(Parser, { const parserOpts = pick(['sourceMap', 'syntacticAnalysis', 'refractorOpts'], this); return await parse(source, parserOpts); } catch (error: any) { - throw new ParserError(`Error parsing "${file.uri}"`, error); + throw new ParserError(`Error parsing "${file.uri}"`, { cause: error }); } }, }, diff --git a/packages/apidom-reference/src/parse/parsers/openapi-yaml-3-0/index.ts b/packages/apidom-reference/src/parse/parsers/openapi-yaml-3-0/index.ts index 6aa8c83245..760bb726da 100644 --- a/packages/apidom-reference/src/parse/parsers/openapi-yaml-3-0/index.ts +++ b/packages/apidom-reference/src/parse/parsers/openapi-yaml-3-0/index.ts @@ -34,7 +34,7 @@ const OpenApiYaml3_0Parser: stampit.Stamp = stampit(Parser, { const parserOpts = pick(['sourceMap', 'refractorOpts'], this); return await parse(source, parserOpts); } catch (error: any) { - throw new ParserError(`Error parsing "${file.uri}"`, error); + throw new ParserError(`Error parsing "${file.uri}"`, { cause: error }); } }, }, diff --git a/packages/apidom-reference/src/parse/parsers/openapi-yaml-3-1/index.ts b/packages/apidom-reference/src/parse/parsers/openapi-yaml-3-1/index.ts index 4861968ba2..ea42d3b700 100644 --- a/packages/apidom-reference/src/parse/parsers/openapi-yaml-3-1/index.ts +++ b/packages/apidom-reference/src/parse/parsers/openapi-yaml-3-1/index.ts @@ -34,7 +34,7 @@ const OpenApiYaml3_1Parser: stampit.Stamp = stampit(Parser, { const parserOpts = pick(['sourceMap', 'refractorOpts'], this); return await parse(source, parserOpts); } catch (error: any) { - throw new ParserError(`Error parsing "${file.uri}"`, error); + throw new ParserError(`Error parsing "${file.uri}"`, { cause: error }); } }, }, diff --git a/packages/apidom-reference/src/parse/parsers/yaml-1-2/index.ts b/packages/apidom-reference/src/parse/parsers/yaml-1-2/index.ts index a43d20676a..562cf8748c 100644 --- a/packages/apidom-reference/src/parse/parsers/yaml-1-2/index.ts +++ b/packages/apidom-reference/src/parse/parsers/yaml-1-2/index.ts @@ -31,7 +31,7 @@ const YamlParser: stampit.Stamp = stampit(Parser, { try { return await parse(source, { sourceMap: this.sourceMap }); } catch (error: any) { - throw new ParserError(`Error parsing "${file.uri}"`, error); + throw new ParserError(`Error parsing "${file.uri}"`, { cause: error }); } }, }, diff --git a/packages/apidom-reference/src/resolve/index.ts b/packages/apidom-reference/src/resolve/index.ts index f3f01343da..a51a8acb96 100644 --- a/packages/apidom-reference/src/resolve/index.ts +++ b/packages/apidom-reference/src/resolve/index.ts @@ -50,7 +50,7 @@ export const resolveApiDOM = async ( const { result } = await plugins.run('resolve', [file, options], resolveStrategies); return result; } catch (error: any) { - throw new ResolverError(`Error while resolving file "${file.uri}"`, error); + throw new ResolverError(`Error while resolving file "${file.uri}"`, { cause: error }); } }; diff --git a/packages/apidom-reference/src/resolve/resolvers/file/index-node.ts b/packages/apidom-reference/src/resolve/resolvers/file/index-node.ts index 5fc92847ac..f2cc3588db 100644 --- a/packages/apidom-reference/src/resolve/resolvers/file/index-node.ts +++ b/packages/apidom-reference/src/resolve/resolvers/file/index-node.ts @@ -33,7 +33,7 @@ const FileResolver: stampit.Stamp = stampit(Resolver, { try { return await promisify(readFile)(fileSystemPath); } catch (error: any) { - throw new ResolverError(`Error opening file "${file.uri}"`, error); + throw new ResolverError(`Error opening file "${file.uri}"`, { cause: error }); } }, }, diff --git a/packages/apidom-reference/src/resolve/resolvers/http-axios/index.ts b/packages/apidom-reference/src/resolve/resolvers/http-axios/index.ts index 6b1fda7e20..a1a227395e 100644 --- a/packages/apidom-reference/src/resolve/resolvers/http-axios/index.ts +++ b/packages/apidom-reference/src/resolve/resolvers/http-axios/index.ts @@ -72,7 +72,7 @@ const HttpResolverAxios: stampit.Stamp = stampit(HttpResolve const response = await client.get(file.uri); return response.data; } catch (error: any) { - throw new ResolverError(`Error downloading "${file.uri}"`, error); + throw new ResolverError(`Error downloading "${file.uri}"`, { cause: error }); } }; }, diff --git a/packages/apidom-reference/src/resolve/util.ts b/packages/apidom-reference/src/resolve/util.ts index 5a8c193ef8..9c2023fb3a 100644 --- a/packages/apidom-reference/src/resolve/util.ts +++ b/packages/apidom-reference/src/resolve/util.ts @@ -29,6 +29,6 @@ export const readFile = async (file: IFile, options: IReferenceOptions): Promise const { result } = await plugins.run('read', [file], resolvers); return result; } catch (error: any) { - throw new ResolverError(`Error while reading file "${file.uri}"`, error); + throw new ResolverError(`Error while reading file "${file.uri}"`, { cause: error }); } }; diff --git a/packages/apidom-reference/src/util/errors/DereferenceError.ts b/packages/apidom-reference/src/util/errors/DereferenceError.ts index 356e96556c..e2215e8d83 100644 --- a/packages/apidom-reference/src/util/errors/DereferenceError.ts +++ b/packages/apidom-reference/src/util/errors/DereferenceError.ts @@ -1,9 +1,7 @@ class DereferenceError extends Error { - public cause: undefined | Error; - - constructor(message: string, cause?: Error) { - super(message); - this.cause = cause; + constructor(message: string, options?: { cause?: Error }) { + super(message, options); + this.cause = this.cause ?? options?.cause; } } diff --git a/packages/apidom-reference/src/util/errors/InvalidSelectorError.ts b/packages/apidom-reference/src/util/errors/InvalidSelectorError.ts index 935b0e039e..5b7d555dc1 100644 --- a/packages/apidom-reference/src/util/errors/InvalidSelectorError.ts +++ b/packages/apidom-reference/src/util/errors/InvalidSelectorError.ts @@ -1,9 +1,7 @@ class InvalidSelectorError extends Error { - public cause: undefined | Error; - - constructor(message: string, cause?: Error) { + constructor(message: string, options?: { cause?: Error }) { super(message); - this.cause = cause; + this.cause = this.cause ?? options?.cause; } } diff --git a/packages/apidom-reference/src/util/errors/NotImplementedError.ts b/packages/apidom-reference/src/util/errors/NotImplementedError.ts index 22d12e65ed..5b5b6be6bc 100644 --- a/packages/apidom-reference/src/util/errors/NotImplementedError.ts +++ b/packages/apidom-reference/src/util/errors/NotImplementedError.ts @@ -1,6 +1,7 @@ class NotImplementedError extends Error { - constructor(message = 'Not Implemented') { + constructor(message = 'Not Implemented', options?: { cause?: Error }) { super(message); + this.cause = this.cause ?? options?.cause; } } diff --git a/packages/apidom-reference/src/util/errors/ParserError.ts b/packages/apidom-reference/src/util/errors/ParserError.ts index 1b95c8b4d5..f03a6b6080 100644 --- a/packages/apidom-reference/src/util/errors/ParserError.ts +++ b/packages/apidom-reference/src/util/errors/ParserError.ts @@ -1,9 +1,7 @@ class ParserError extends Error { - public cause: undefined | Error; - - constructor(message: string, cause?: Error) { + constructor(message: string, options?: { cause?: Error }) { super(message); - this.cause = cause; + this.cause = this.cause ?? options?.cause; } } diff --git a/packages/apidom-reference/src/util/errors/PluginError.ts b/packages/apidom-reference/src/util/errors/PluginError.ts index 6dcd220195..4b67e7d28e 100644 --- a/packages/apidom-reference/src/util/errors/PluginError.ts +++ b/packages/apidom-reference/src/util/errors/PluginError.ts @@ -1,12 +1,10 @@ class PluginError extends Error { - public cause: Error; - public plugin: any; - constructor(message: string, cause: Error, plugin: any) { + constructor(message: string, options: { cause?: Error; plugin: any }) { super(message); - this.cause = cause; - this.plugin = plugin; + this.cause = this.cause ?? options?.cause; + this.plugin = options.plugin; } } diff --git a/packages/apidom-reference/src/util/errors/ResolverError.ts b/packages/apidom-reference/src/util/errors/ResolverError.ts index c8cc956c0b..9b6746cd7b 100644 --- a/packages/apidom-reference/src/util/errors/ResolverError.ts +++ b/packages/apidom-reference/src/util/errors/ResolverError.ts @@ -1,9 +1,7 @@ class ResolverError extends Error { - public cause: undefined | Error; - - constructor(message: string, cause?: Error) { + constructor(message: string, options?: { cause?: Error }) { super(message); - this.cause = cause; + this.cause = this.cause ?? options?.cause; } } diff --git a/packages/apidom-reference/src/util/plugins.ts b/packages/apidom-reference/src/util/plugins.ts index cb183df0d4..85a4688a86 100644 --- a/packages/apidom-reference/src/util/plugins.ts +++ b/packages/apidom-reference/src/util/plugins.ts @@ -33,7 +33,7 @@ export const run = async (method: string, parameters: any[], plugins: any[]): Pr const result = await plugin[method].call(plugin, ...parameters); // eslint-disable-line no-await-in-loop return { plugin, result }; } catch (error: any) { - lastError = new PluginError('Error while running plugin', error, plugin); + lastError = new PluginError('Error while running plugin', { cause: error, plugin }); } }