Skip to content

Commit

Permalink
More readable errors involving Uint8Arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Aug 24, 2021
1 parent a662490 commit b6a061e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/logger/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ export enum ErrorCode {
TRANSACTION_REPLACED = "TRANSACTION_REPLACED",
};

const HEX = "0123456789abcdef";

export class Logger {
readonly version: string;

Expand Down Expand Up @@ -195,8 +197,18 @@ export class Logger {

const messageDetails: Array<string> = [];
Object.keys(params).forEach((key) => {
const value = params[key];
try {
messageDetails.push(key + "=" + JSON.stringify(params[key]));
if (value instanceof Uint8Array) {
let hex = "";
for (let i = 0; i < value.length; i++) {
hex += HEX[value[i] >> 4];
hex += HEX[value[i] & 0x0f];
}
messageDetails.push(key + "=Uint8Array(0x" + hex + ")");
} else {
messageDetails.push(key + "=" + JSON.stringify(value));
}
} catch (error) {
messageDetails.push(key + "=" + JSON.stringify(params[key].toString()));
}
Expand Down

0 comments on commit b6a061e

Please sign in to comment.