diff --git a/packages/exo/src/exo-tools.js b/packages/exo/src/exo-tools.js index 41b83a04be..56fd439968 100644 --- a/packages/exo/src/exo-tools.js +++ b/packages/exo/src/exo-tools.js @@ -57,8 +57,8 @@ const PassableMethodGuard = M.call().rest(M.any()).returns(M.any()); * @param {Passable[]} syncArgs * @param {MatchConfig} matchConfig * @param {string} [label] - * @returns {Passable[]} Returns the args that should be passed to the - * raw method + * @returns {import('@endo/pass-style').Passable[]} + * Returns the args that should be passed to the raw method. */ const defendSyncArgs = (syncArgs, matchConfig, label = undefined) => { const { @@ -69,7 +69,8 @@ const defendSyncArgs = (syncArgs, matchConfig, label = undefined) => { redactedIndices, } = matchConfig; - // Use syncArgs if possible, but copy it when necessary to implement redactions. + // Use syncArgs if possible, but copy it when necessary to implement + // redactions. let matchableArgs = syncArgs; if (restArgGuardIsRaw && syncArgs.length > declaredLen) { const restLen = syncArgs.length - declaredLen; @@ -96,11 +97,11 @@ const defendSyncArgs = (syncArgs, matchConfig, label = undefined) => { if (hasRestArgGuard) { return syncArgs; } - if (syncArgs.length <= declaredLen) { - return syncArgs; - } - // Ignore extraneous arguments, as a JS function call would do. - return syncArgs.slice(0, declaredLen); + syncArgs.length <= declaredLen || + Fail`${q(label)} accepts at most ${q(declaredLen)} arguments, not ${q( + syncArgs.length, + )}: ${syncArgs}`; + return syncArgs; }; /** diff --git a/packages/exo/test/test-heap-classes.js b/packages/exo/test/test-heap-classes.js index c6c3525cf7..5d5206f4f8 100644 --- a/packages/exo/test/test-heap-classes.js +++ b/packages/exo/test/test-heap-classes.js @@ -16,12 +16,15 @@ const NoExtraI = M.interface('NoExtra', { }); test('what happens with extra arguments', t => { - const exo = makeExo('WithExtra', NoExtraI, { + const exo = makeExo('NoExtraArgs', NoExtraI, { foo(x) { t.is(x, undefined); }, }); - exo.foo('an extra arg'); + t.throws(() => exo.foo('an extra arg'), { + message: + '"In \\"foo\\" method of (NoExtraArgs)" accepts at most 0 arguments, not 1: ["an extra arg"]', + }); }); const OptionalArrayI = M.interface('OptionalArray', {