Skip to content

Commit

Permalink
feat: show debug data on zenroom errors (#67)
Browse files Browse the repository at this point in the history
* feat: show debug data on zenroom errors

* chore: remove double print
  • Loading branch information
puria authored Mar 1, 2024
1 parent 10ebcc9 commit 825c403
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,41 @@ export const reportZenroomError = (
l.error('Slangroom Syntax Error ', error.message);
return error.message;
} else {
l.error(error);
l.fatal(error);
return error.message;
}
};

/*
const debugZen = (type: 'J64 TRACE: ' | 'J64 HEAP: ', l: Logger<ILogObj>, error: Error) => {
const trace = JSON.parse(error.message).filter((l: string) => l.startsWith(type));
if (trace.length) {
const content = trace[0].split(type)[1].replaceAll("'", '');
const decodedContent = Buffer.from(content, 'base64').toString('utf8');
console.table(JSON.parse(decodedContent));
}
};
*/

import _ from 'lodash';


const debugZen = (type: 'J64 TRACE: ' | 'J64 HEAP: ', l: Logger<ILogObj>, error: Error) => {
const trace = JSON.parse(error.message).filter((l: string) => l.startsWith(type));
if (trace.length) {
const content = trace[0].split(type)[1].replaceAll("'", '');
const decodedContent = JSON.parse(Buffer.from(content, 'base64').toString('utf8'));

if (type === 'J64 HEAP: ') {
l.debug('J64 HEAP: ', decodedContent);
console.table(_.omit(decodedContent, 'GIVEN_data'));
const transposedContent = _.zip(Object.keys(decodedContent['GIVEN_data']), Object.values(decodedContent['GIVEN_data']));
console.table(transposedContent);
return;
}

const transposedContent = _.zip(Object.keys(decodedContent), Object.values(decodedContent));
console.table(transposedContent);
}
};

0 comments on commit 825c403

Please sign in to comment.