-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(error): errors now point to the Node that caused or threw them. …
…Errors caused by the evaluated code itself such as ThrowStatements will produce ThrownError objects that point to the original error as well as the Node that caused or threw it. Fixes #8
- Loading branch information
Showing
37 changed files
with
137 additions
and
68 deletions.
There are no files selected for viewing
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
2 changes: 2 additions & 0 deletions
2
src/interpreter/environment/i-create-sanitized-environment-options.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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import {IEvaluatePolicySanitized} from "../policy/i-evaluate-policy"; | ||
import {IndexLiteral} from "../literal/literal"; | ||
import {Node} from "typescript"; | ||
|
||
export interface ICreateSanitizedEnvironmentOptions { | ||
policy: IEvaluatePolicySanitized; | ||
env: IndexLiteral; | ||
getCurrentNode (): Node; | ||
} |
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,11 +1,18 @@ | ||
import {IEvaluationErrorOptions} from "./i-evaluation-error-options"; | ||
import {Node} from "typescript"; | ||
|
||
/** | ||
* A Base class for EvaluationErrors | ||
*/ | ||
export class EvaluationError extends Error { | ||
constructor ({message}: IEvaluationErrorOptions = {}) { | ||
/** | ||
* The node that caused or thew the error | ||
*/ | ||
public readonly node: Node; | ||
|
||
constructor ({node, message}: IEvaluationErrorOptions) { | ||
super(message); | ||
Error.captureStackTrace(this, this.constructor); | ||
this.node = node; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/interpreter/error/evaluation-error/i-evaluation-error-options.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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import {Node} from "typescript"; | ||
|
||
export interface IEvaluationErrorOptions { | ||
node: Node; | ||
message?: string; | ||
} |
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
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
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
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {IEvaluationErrorOptions} from "../evaluation-error/i-evaluation-error-options"; | ||
|
||
export interface IThrownErrorOptions extends IEvaluationErrorOptions { | ||
originalError: Error; | ||
} |
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,18 @@ | ||
import {EvaluationError} from "../evaluation-error/evaluation-error"; | ||
import {IThrownErrorOptions} from "./i-thrown-error-options"; | ||
|
||
/** | ||
* An Error that represents an error thrown from within the code that is being evaluated. | ||
*/ | ||
export class ThrownError extends EvaluationError { | ||
/** | ||
* The originally thrown Error | ||
* @type {Error} | ||
*/ | ||
public readonly originalError: Error; | ||
|
||
constructor ({originalError, node, message = originalError.message}: IThrownErrorOptions) { | ||
super({message, node}); | ||
this.originalError = originalError; | ||
} | ||
} |
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
2 changes: 0 additions & 2 deletions
2
src/interpreter/error/unexpected-node-error/i-unexpected-node-error-options.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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
import {Node} from "typescript"; | ||
import {IEvaluationErrorOptions} from "../evaluation-error/i-evaluation-error-options"; | ||
|
||
export interface IUnexpectedNodeErrorOptions extends IEvaluationErrorOptions { | ||
node: Node; | ||
} |
9 changes: 2 additions & 7 deletions
9
src/interpreter/error/unexpected-node-error/unexpected-node-error.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 |
---|---|---|
@@ -1,18 +1,13 @@ | ||
import {Node, SyntaxKind} from "typescript"; | ||
import {SyntaxKind} from "typescript"; | ||
import {EvaluationError} from "../evaluation-error/evaluation-error"; | ||
import {IUnexpectedNodeErrorOptions} from "./i-unexpected-node-error-options"; | ||
|
||
/** | ||
* An Error that can be thrown when an unexpected node is encountered | ||
*/ | ||
export class UnexpectedNodeError extends EvaluationError { | ||
/** | ||
* The node that was unexpected in the context that spawned this error | ||
*/ | ||
public readonly node: Node; | ||
|
||
constructor ({node, message = `Unexpected Node: '${SyntaxKind[node.kind]}'`}: IUnexpectedNodeErrorOptions) { | ||
super({message}); | ||
this.node = node; | ||
super({message, node}); | ||
} | ||
} |
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
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
Oops, something went wrong.