-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(json-path): use error hierarchy and metadata when throwing errors (
- Loading branch information
Showing
11 changed files
with
126 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/apidom-json-path/src/errors/EvaluationJsonPathError.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Element, hasElementSourceMap, toValue } from '@swagger-api/apidom-core'; | ||
import { ApiDOMErrorOptions } from '@swagger-api/apidom-error'; | ||
|
||
import JsonPathError from './JsonPathError'; | ||
|
||
export interface EvaluationJsonPathErrorOptions<T extends Element> extends ApiDOMErrorOptions { | ||
path: string | string[]; | ||
element: T; | ||
} | ||
|
||
class EvaluationJsonPathError<T extends Element> extends JsonPathError { | ||
public readonly path!: string | string[]; | ||
|
||
public readonly element!: string; | ||
|
||
public readonly elementSourceMap?: [[number, number, number], [number, number, number]]; | ||
|
||
constructor(message?: string, structuredOptions?: EvaluationJsonPathErrorOptions<T>) { | ||
super(message, structuredOptions); | ||
|
||
if (typeof structuredOptions !== 'undefined') { | ||
this.path = structuredOptions.path; | ||
this.element = structuredOptions.element.element; | ||
if (hasElementSourceMap(structuredOptions.element)) { | ||
this.elementSourceMap = toValue(structuredOptions.element.getMetaProperty('sourceMap')); | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default EvaluationJsonPathError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { ApiDOMStructuredError } from '@swagger-api/apidom-error'; | ||
|
||
class JsonPathError extends ApiDOMStructuredError {} | ||
|
||
export default JsonPathError; |
31 changes: 31 additions & 0 deletions
31
packages/apidom-json-path/src/errors/MultiEvaluationJsonPathError.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Element, hasElementSourceMap, toValue } from '@swagger-api/apidom-core'; | ||
import { ApiDOMErrorOptions } from '@swagger-api/apidom-error'; | ||
|
||
import JsonPathError from './JsonPathError'; | ||
|
||
export interface MultiEvaluationJsonPathErrorOptions<T extends Element> extends ApiDOMErrorOptions { | ||
paths: string[] | string[][]; | ||
element: T; | ||
} | ||
|
||
class MultiEvaluationJsonPathError<T extends Element> extends JsonPathError { | ||
public readonly paths!: string[] | string[][]; | ||
|
||
public readonly element!: string; | ||
|
||
public readonly elementSourceMap?: [[number, number, number], [number, number, number]]; | ||
|
||
constructor(message?: string, structuredOptions?: MultiEvaluationJsonPathErrorOptions<T>) { | ||
super(message, structuredOptions); | ||
|
||
if (typeof structuredOptions !== 'undefined') { | ||
this.paths = structuredOptions.paths; | ||
this.element = structuredOptions.element.element; | ||
if (hasElementSourceMap(structuredOptions.element)) { | ||
this.elementSourceMap = toValue(structuredOptions.element.getMetaProperty('sourceMap')); | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default MultiEvaluationJsonPathError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
export { default as EvaluationJsonPathError } from './errors/EvaluationJsonPathError'; | ||
export type { EvaluationJsonPathErrorOptions } from './errors/EvaluationJsonPathError'; | ||
export { default as MultiEvaluationJsonPathError } from './errors/MultiEvaluationJsonPathError'; | ||
export type { MultiEvaluationJsonPathErrorOptions } from './errors/MultiEvaluationJsonPathError'; | ||
export { default as evaluate } from './evaluate'; | ||
export { default as evaluateMulti } from './evaluate-multi'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters