Skip to content

Commit

Permalink
Merge pull request #1066 from floriancargoet/patch-2
Browse files Browse the repository at this point in the history
Fixed arguments error reporting
  • Loading branch information
smwhr authored Jun 27, 2024
2 parents 6b64698 + b474c46 commit 37cc001
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/engine/StoryState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1134,10 +1134,10 @@ export class StoryState {
) {
throw new Error(
"ink arguments when calling EvaluateFunction / ChoosePathStringWithParameters must be" +
"number, string, bool or InkList. Argument was " +
(nullIfUndefined(arguments[i]) === null)
? "null"
: arguments[i].constructor.name
"number, string, bool or InkList. Argument was " +
(nullIfUndefined(args[i]) === null
? "null"
: args[i].constructor.name)
);
}

Expand Down
16 changes: 16 additions & 0 deletions src/tests/specs/inkjs/engine/Integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,22 @@ describe("Integration", () => {
expect(context.story.EvaluateFunction("fn_echo", [5.3])).toEqual(5.3);
});

it("should report invalid params passed to ink functions", () => {
class BadParameter {}
expect(() =>
context.story.EvaluateFunction("fn_params", [new BadParameter()])
).toThrow("Argument was BadParameter");
});

it("should report invalid params passed to knots/stitches", () => {
class BadParameter {}
expect(() =>
context.story.ChoosePathString("stitch_with_param", undefined, [
new BadParameter(),
])
).toThrow("Argument was BadParameter");
});

it("should return output and return value from ink function calls", () => {
expect(context.story.EvaluateFunction("fn_print", [], true)).toEqual({
output: "function called\n",
Expand Down

0 comments on commit 37cc001

Please sign in to comment.