Skip to content

Commit b474c46

Browse files
Fixed arguments error reporting
1 parent 6b64698 commit b474c46

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/engine/StoryState.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1134,10 +1134,10 @@ export class StoryState {
11341134
) {
11351135
throw new Error(
11361136
"ink arguments when calling EvaluateFunction / ChoosePathStringWithParameters must be" +
1137-
"number, string, bool or InkList. Argument was " +
1138-
(nullIfUndefined(arguments[i]) === null)
1139-
? "null"
1140-
: arguments[i].constructor.name
1137+
"number, string, bool or InkList. Argument was " +
1138+
(nullIfUndefined(args[i]) === null
1139+
? "null"
1140+
: args[i].constructor.name)
11411141
);
11421142
}
11431143

src/tests/specs/inkjs/engine/Integration.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,22 @@ describe("Integration", () => {
175175
expect(context.story.EvaluateFunction("fn_echo", [5.3])).toEqual(5.3);
176176
});
177177

178+
it("should report invalid params passed to ink functions", () => {
179+
class BadParameter {}
180+
expect(() =>
181+
context.story.EvaluateFunction("fn_params", [new BadParameter()])
182+
).toThrow("Argument was BadParameter");
183+
});
184+
185+
it("should report invalid params passed to knots/stitches", () => {
186+
class BadParameter {}
187+
expect(() =>
188+
context.story.ChoosePathString("stitch_with_param", undefined, [
189+
new BadParameter(),
190+
])
191+
).toThrow("Argument was BadParameter");
192+
});
193+
178194
it("should return output and return value from ink function calls", () => {
179195
expect(context.story.EvaluateFunction("fn_print", [], true)).toEqual({
180196
output: "function called\n",

0 commit comments

Comments
 (0)