Skip to content

Commit

Permalink
feat: handle kernel failures more gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
FUDCo committed Jun 10, 2021
1 parent bf5f46b commit 8d03175
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions packages/swingset-runner/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,14 @@ export async function main() {
break;
}
case 'step': {
const steps = await controller.step();
swingStore.commit();
swingStore.close();
log(`runner stepped ${steps} crank${steps === 1 ? '' : 's'}`);
try {
const steps = await controller.step();
swingStore.commit();
swingStore.close();
log(`runner stepped ${steps} crank${steps === 1 ? '' : 's'}`);
} catch (err) {
kernelFailure(err);
}
break;
}
case 'shell': {
Expand Down Expand Up @@ -522,9 +526,13 @@ export async function main() {
cli.defineCommand('step', {
help: 'Step the swingset one crank, without commit',
action: async () => {
const steps = await controller.step();
log(steps ? 'stepped one crank' : "didn't step, queue is empty");
cli.displayPrompt();
try {
const steps = await controller.step();
log(steps ? 'stepped one crank' : "didn't step, queue is empty");
cli.displayPrompt();
} catch (err) {
kernelFailure(err);
}
},
});
break;
Expand Down Expand Up @@ -591,13 +599,17 @@ export async function main() {
}
while (requestedSteps > 0) {
requestedSteps -= 1;
// eslint-disable-next-line no-await-in-loop
const stepped = await controller.step();
if (stepped < 1) {
break;
try {
// eslint-disable-next-line no-await-in-loop
const stepped = await controller.step();
if (stepped < 1) {
break;
}
crankNumber += stepped;
actualSteps += stepped;
} catch (err) {
kernelFailure(err);
}
crankNumber += stepped;
actualSteps += stepped;
if (doDumps) {
kernelStateDump();
}
Expand Down Expand Up @@ -658,6 +670,11 @@ export async function main() {
return [totalSteps, readClock() - startTime];
}

function kernelFailure(err) {
log(`kernel failure in crank ${crankNumber}: ${err}`, err);
process.exit(1);
}

async function commandRun(stepLimit, runInBlockMode) {
if (doDumps) {
kernelStateDump();
Expand Down

0 comments on commit 8d03175

Please sign in to comment.