Skip to content

Commit

Permalink
feat(xsnap worker): pass console log messages to manager
Browse files Browse the repository at this point in the history
 - prune 'starting xsnap' log msg (per code review)
 - handle rejection in ManagerPort.handler
  • Loading branch information
dckc committed Jan 23, 2021
1 parent c3da176 commit ad5ca74
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
1 change: 0 additions & 1 deletion packages/SwingSet/src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ export async function makeSwingsetController(

const { xsnapBundles = await buildXsBundles() } = {}; // @@@ options?
const startXSnap = (name, handleCommand) => {
console.log('starting xsnap for', name);
const worker = xsnap({
os: osType(),
spawn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ export function makeXsSubprocessFactory({
const [scTag, ...vatSyscallArgs] = args;
return handleSyscall([scTag, ...vatSyscallArgs]);
}
case 'console': {
const [level, tag, ...rest] = args;
if (typeof level === 'string' && level in console) {
console[level](tag, ...rest);
} else {
console.error('bad console level', level);
}
return ['ok'];
}
case 'testLog':
testLog(...args);
return ['OK'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,19 @@ function ManagerPort(issueCommand) {
/** @type { (f: AsyncHandler) => ((msg: ArrayBuffer) => { result?: ArrayBuffer })} */
handler: f => msg => {
const report = {};
f(decode(msg)).then(item => {
workerLog('result', item);
report.result = encode(item);
}); // TODO: .catch?!?!
f(decode(msg))
.then(item => {
workerLog('result', item);
report.result = encode(item);
})
.catch(err => {
report.result = encode(['err', err.message]);
});
return report;
},
});
}

function makeConsole(_tag) {
const log = console; // TODO: anylogger(tag);
const cons = {
debug: log.debug,
log: log.log,
info: log.info,
warn: log.warn,
error: log.error,
};
return harden(cons);
}

/**
* @param { (value: void) => void } f
* @param { string } errmsg
Expand Down Expand Up @@ -119,6 +111,19 @@ function makeWorker(port) {
return doProcess(['notify', primaryVpid, resolutions], errmsg);
}

function makeConsole(tag) {
const log = level => (...args) =>
port.send(['console', level, tag, ...args]);
const cons = {
debug: log('debug'),
log: log('log'),
info: log('info'),
warn: log('warn'),
error: log('error'),
};
return harden(cons);
}

/**
* @param {unknown} vatID
* @param {unknown} bundle
Expand Down

0 comments on commit ad5ca74

Please sign in to comment.