Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Bug: TypeError when logging GraphQLError #269

Open
Mordred opened this issue Oct 5, 2023 · 0 comments
Open

Bug: TypeError when logging GraphQLError #269

Mordred opened this issue Oct 5, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@Mordred
Copy link

Mordred commented Oct 5, 2023

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

@Mordred Mordred added the bug Something isn't working label Oct 5, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant