Skip to content
New issue

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

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

Already on GitHub? Sign in 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
[email protected]
[email protected]

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant