Skip to content

Commit

Permalink
fix: improve command device support
Browse files Browse the repository at this point in the history
Propagate inboundHandler errors better.  Prevent asynchronous
rejection errors.
  • Loading branch information
michaelfig committed Mar 17, 2020
1 parent 068b74c commit c70b8a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/SwingSet/src/devices/command-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function setup(syscall, state, helpers, endowments) {
const body = JSON.parse(`${bodyString}`);
SO(inboundHandler).inbound(Nat(count), body);
} catch (e) {
console.log(`error during inboundCallback: ${e}`);
console.log(`error during inboundCallback`, e);
throw new Error(`error during inboundCallback: ${e}`);
}
});
Expand All @@ -33,6 +33,10 @@ export default function setup(syscall, state, helpers, endowments) {
},

sendResponse(count, isReject, obj) {
if (isReject && obj instanceof Error) {
console.log('inboundHandler rejected with:', obj);
obj = { message: obj.message };
}
try {
deliverResponse(count, isReject, JSON.stringify(obj));
} catch (e) {
Expand Down
13 changes: 11 additions & 2 deletions packages/cosmic-swingset/lib/ag-solo/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,19 @@ async function buildSwingset(
// this promise could take an arbitrarily long time to resolve, so don't
// wait on it
const p = cm.inboundCommand(obj);

// Register a handler so that we don't get complaints about
// asynchronously-handled callbacks.
p.catch(_ => {});

// TODO: synchronize this somehow, make sure it doesn't overlap with the
// processKernel() call in deliverInbound()
// processKernel() call in deliverInboundToMbx()
await processKernel();
return p;

// Rethrow any exception so that our caller must handle it.
return p.catch(e => {
throw e;
});
}

const intervalMillis = 1200;
Expand Down

0 comments on commit c70b8a1

Please sign in to comment.