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

ConsoleLogger prints an array of an object as [object Object]. #10280

Closed
2 of 15 tasks
yukukotani opened this issue Sep 14, 2022 · 4 comments
Closed
2 of 15 tasks

ConsoleLogger prints an array of an object as [object Object]. #10280

yukukotani opened this issue Sep 14, 2022 · 4 comments
Labels
needs triage This issue has not been looked into

Comments

@yukukotani
Copy link
Contributor

yukukotani commented Sep 14, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

ConsoleLogger prints an object correctly. But an array of an object is printed as [object Object].

Minimum reproduction code

https://stackblitz.com/edit/nestjs-typescript-starter-nglkvt?file=src%2Fapp.controller.ts

Steps to reproduce

No response

Expected behavior

An array of an object should be printed with JSON.stringify.

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

No response

Packages versions

[System Information]
OS Version : Linux 5.0
NodeJS Version : v16.14.2
NPM Version : 7.17.0

[Nest CLI]
Nest CLI Version : 9.0.0

[Nest Platform Information]
platform-express version : 9.0.0
schematics version : 9.0.0
testing version : 9.0.0
common version : 9.0.0
core version : 9.0.0
cli version : 9.0.0

Node.js version

No response

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@yukukotani yukukotani added the needs triage This issue has not been looked into label Sep 14, 2022
@yukukotani yukukotani changed the title ConsoleLogger prints an array of an object incorrectly ConsoleLogger prints an array of an object as [object Object]. Sep 14, 2022
@jmcdo29
Copy link
Member

jmcdo29 commented Sep 14, 2022

Looks like this comes from our isPlainObject check, specifically where we check ctor instanceof ctor. With an array, Array instanceof Array comes back false it would seem. With this, our colorize method tries to .toString() the [{ key: 'obj array' }] which results in [object Object] like you're seeing. We can add an earlier check in the isPlainObject method for Array.isArray(fn) and return true if so, but I'm not sure what other implications that may have elsewhere in the internals

@kamilmysliwiec
Copy link
Member

Following what @jmcdo29 wrote above, would you like to create a PR for this change @yukukotani?

@yukukotani
Copy link
Contributor Author

@jmcdo29 @kamilmysliwiec Thanks for the explanation! Of course, I'll work on this.

yukukotani added a commit to yukukotani/nest that referenced this issue Sep 17, 2022
stringify arrays as json to avoid [object Object]

Close nestjs#10280
@kamilmysliwiec
Copy link
Member

Let's track this here #10291

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into
Projects
None yet
Development

No branches or pull requests

3 participants