fullstack-build/tslog

Bug: TypeError when logging GraphQLError

Mordred opened this issue · 0 comments

Describe the bug
Uncaught TypeError:

Uncaught TypeError: Cannot convert object to primitive value
    at Array.join (<anonymous>)
    at prettyFormatErrorObj (/project/node_modules/tslog/dist/cjs/runtime/nodejs/index.js:107:14)
    at maskedArgs.reduce.args (/project/node_modules/tslog/dist/cjs/runtime/nodejs/index.js:89:43)
    at Array.reduce (<anonymous>)
    at Object.prettyFormatLogObj (/project/node_modules/tslog/dist/cjs/runtime/nodejs/index.js:88:23)
    at Logger.log (/project/node_modules/tslog/dist/cjs/BaseLogger.js:113:77)
    at Logger.error (/project/node_modules/tslog/dist/cjs/index.js:49:22)

Main problem is Array.join(', ') here: https://github.com/fullstack-build/tslog/blob/master/src/runtime/nodejs/index.ts#L135
because GraphQLError is using Object.create(null) for extensions property: https://github.com/graphql/graphql-js/blob/main/src/error/GraphQLError.ts#L125

[Object.create(null)].jon(', ') // throws an error

Maybe filter out such values before joining? e.g.

.filter((v) => Object.getPrototypeOf(v) !== null)

To Reproduce

const { Logger } = require('tslog');
const { GraphQLError } = require('graphql');

const log = new Logger();
log.error(new GraphQLError("Error in your graphql server"));

Expected behavior
Logger should not throw an error.

Additional context
tslog@4.9.2
graphql@16.8.1

Node.js Version
v18.16.1

OS incl. Version
macOS 13.5.2