Skip to content

Commit

Permalink
Fix crash when encountering bigint (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron authored Mar 16, 2023
1 parent 7787a00 commit bec1b45
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/Logger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ describe('Logger', () => {
sinon.restore();
});

it('does not crash on bigint', () => {
logger = new Logger();
//should not throw
expect(
logger['buildLogMessage']('debug', {
bigNumber: BigInt('123456789123456789')
}).argsText
).to.eql('{"bigNumber":"123456789123456789"}');
});

it('uses LogLevel.log by default', () => {
logger = new Logger();
expect(logger.logLevel).to.eql('log');
Expand Down
5 changes: 4 additions & 1 deletion src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ export class Logger {
argsText += (arg as RegExp).toString();
} else {
argsText += safeJsonStringify(
serializeError(arg)
serializeError(arg),
(_, value) => {
return typeof value === 'bigint' ? value.toString() : value;
}
);
}
break;
Expand Down
2 changes: 1 addition & 1 deletion src/transports/ConsoleTransport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LogMessage } from '..';
import type { LogMessage } from '../Logger';

export class ConsoleTransport {
pipe(message: LogMessage) {
Expand Down
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
"exclude": [
"node_modules",
"src/**/*.spec.ts"
]
],
"ts-node": {
"transpileOnly": true
}
}

0 comments on commit bec1b45

Please sign in to comment.