Skip to content

Commit

Permalink
feat(marshal): allow marshalSaveError function to be specified
Browse files Browse the repository at this point in the history
The default for this is the same "Temporary logging of sent error"
console.log.  However, this allows the caller to decide to do
something different to save the errors.
  • Loading branch information
michaelfig committed Mar 16, 2021
1 parent 8ea694b commit c93bb04
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
16 changes: 9 additions & 7 deletions packages/marshal/src/marshal.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,14 @@ const defaultSlotToValFn = (x, _) => x;
export function makeMarshal(
convertValToSlot = defaultValToSlotFn,
convertSlotToVal = defaultSlotToValFn,
{ marshalName = 'anon-marshal', errorTagging = 'on' } = {},
{
marshalName = 'anon-marshal',
errorTagging = 'on',
// We prefer that the caller instead log to somewhere hidden
// to be revealed when correlating with the received error.
marshalSaveError = err =>
console.log('Temporary logging of sent error', err),
} = {},
) {
assert.typeof(marshalName, 'string');
assert(
Expand Down Expand Up @@ -743,12 +750,7 @@ export function makeMarshal(
if (errorTagging === 'on') {
const errorId = nextErrorId();
assert.note(val, X`Sent as ${errorId}`);
// TODO we need to instead log to somewhere hidden
// to be revealed when correlating with the received error.
// By sending this to `console.log`, under swingset this is
// enabled by `agoric start --reset -v` and not enabled without
// the `-v` flag.
console.log('Temporary logging of sent error', val);
marshalSaveError(val);
return harden({
[QCLASS]: 'error',
errorId,
Expand Down
3 changes: 2 additions & 1 deletion packages/marshal/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@
/**
* @typedef MakeMarshalOptions
* @property {string=} marshalName
* @property {('on'|'off')=} errorTagging
* @property {'on'|'off'=} errorTagging
* @property {(err: Error) => void=} marshalSaveError
*/

// /////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit c93bb04

Please sign in to comment.