Skip to content

Commit

Permalink
Until While specs and error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolas Howard committed Feb 29, 2024
1 parent 758adb4 commit 858c0e4
Show file tree
Hide file tree
Showing 9 changed files with 726 additions and 18 deletions.
26 changes: 24 additions & 2 deletions dist/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/bundle.js.map

Large diffs are not rendered by default.

26 changes: 24 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/index.js.map

Large diffs are not rendered by default.

21 changes: 19 additions & 2 deletions src/attributes/guards/Until.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,24 @@ export default class Until extends Guard {
);
}

// Call the condition function to determine whether this guard is satisfied.
return !!!conditionFuncInvoker(this.args);
let conditionFunctionResult;

try {
// Call the guard condition function to determine the state of this node, the result of which should be a boolean.
conditionFunctionResult = conditionFuncInvoker(this.args);
} catch (error) {
// The user was naughty and threw something.
throw new Error(`guard condition function '${this.getCondition()}' threw '${error}'`);
}

// The result of calling the guard condition function must be a boolean value.
if (typeof conditionFunctionResult !== "boolean") {
throw new Error(
`expected guard condition function '${this.getCondition()}' to return a boolean but returned '${conditionFunctionResult}'`
);
}

// Return whether this guard is satisfied.
return !conditionFunctionResult;
};
}
21 changes: 19 additions & 2 deletions src/attributes/guards/While.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,24 @@ export default class While extends Guard {
);
}

// Call the condition function to determine whether this guard is satisfied.
return !!conditionFuncInvoker(this.args);
let conditionFunctionResult;

try {
// Call the guard condition function to determine the state of this node, the result of which should be a boolean.
conditionFunctionResult = conditionFuncInvoker(this.args);
} catch (error) {
// The user was naughty and threw something.
throw new Error(`guard condition function '${this.getCondition()}' threw '${error}'`);
}

// The result of calling the guard condition function must be a boolean value.
if (typeof conditionFunctionResult !== "boolean") {
throw new Error(
`expected guard condition function '${this.getCondition()}' to return a boolean but returned '${conditionFunctionResult}'`
);
}

// Return whether this guard is satisfied.
return conditionFunctionResult;
};
}
Loading

0 comments on commit 858c0e4

Please sign in to comment.