Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make userSeat.getPayout(foo) throw if foo is not present #10738

Merged
merged 5 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/zoe/src/zoeService/originalZoeSeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ const assertHasNotExited = (c, msg) => {
assert(!c.state.instanceAdminHelper.hasExited(c.facets.zoeSeatAdmin), msg);
};

const getPayoutOrThrow = (state, keyword) => {
state.payouts[keyword] || Fail`No payout for ${keyword}`;
return state.payouts[keyword];
};

/**
* declareOldZoeSeatAdminKind declares an exo for the original kind of ZoeSeatKit.
* This version creates a reference cycle that garbage collection can't remove
Expand Down Expand Up @@ -289,8 +294,8 @@ export const declareOldZoeSeatAdminKind = (baggage, makeDurablePublishKit) => {
// doExit(), which ensures that finalPayouts() has set state.payouts.
return E.when(
state.subscriber.subscribeAfter(),
() => state.payouts[keyword],
() => state.payouts[keyword],
() => getPayoutOrThrow(state, keyword),
() => getPayoutOrThrow(state, keyword),
);
},

Expand Down
9 changes: 7 additions & 2 deletions packages/zoe/src/zoeService/zoeSeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ export const makeZoeSeatAdminFactory = baggage => {
*/
const ephemeralOfferResultStore = new WeakMap();

const getPayoutOrThrow = (state, keyword) => {
state.payouts[keyword] || Fail`No payout for ${keyword}`;
return state.payouts[keyword];
};

const makeZoeSeatAdmin = prepareExoClassKit(
baggage,
'ZoeSeatAdmin',
Expand Down Expand Up @@ -143,8 +148,8 @@ export const makeZoeSeatAdminFactory = baggage => {
// doExit(), which ensures that finalPayouts() has set state.payouts.
return E.when(
state.subscriber.subscribeAfter(),
() => state.payouts[keyword],
() => state.payouts[keyword],
() => getPayoutOrThrow(state, keyword),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use NonNullish() instead of a new function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When switching to NonNullish, please remember to use the second optional optDetails argument so the error message remains informative.

() => getPayoutOrThrow(state, keyword),
);
},

Expand Down
4 changes: 4 additions & 0 deletions packages/zoe/test/unitTests/zcf/zcf.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,10 @@ test(`userSeat.getPayouts, getPayout from zcf.makeEmptySeatKit`, async t => {
const payoutAP = E(userSeat).getPayout('A');
const payoutBP = E(userSeat).getPayout('B');

await t.throwsAsync(() => E(userSeat).getPayout('C'), {
message: /No payout for "C"/,
});

t.deepEqual(await payoutPs.A, await payoutAP);
t.deepEqual(await payoutPs.B, await payoutBP);

Expand Down
Loading