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

Wrapped errors wrongly apply formatting #109

Closed
pi0 opened this issue Feb 1, 2021 · 12 comments
Closed

Wrapped errors wrongly apply formatting #109

pi0 opened this issue Feb 1, 2021 · 12 comments
Labels
bug Something isn't working

Comments

@pi0
Copy link
Member

pi0 commented Feb 1, 2021

Using using wrap* helpers, we implicitly assume first argument as consola logObj format which might end with formatting errors. (nuxt/nuxt#8741)

Reproduction

const consola = require('consola')

const error = new Error('boom')
const errorObj = {
  date: new Date().toISOString(),
  level: 'error',
  message: error.message,
  error: { stack: error.stack, message: error.message }
}

console.log(errorObj)
consola.wrapAll()
console.log(errorObj)

Workarounds

  1. Use different field name than message, error
  2. console.log(JSON.stringify(errorObj, null, 2))
  3. console.log('', errorObj)
  4. consola.restoreAll()
@gkatsanos
Copy link

gkatsanos commented Feb 2, 2021

unfortunately workarounds dont work for us as they don't generate valid JSON (at least Datadog doesnt see it as such).
The only thing that seems to work is restoreAll() ...

@gkatsanos
Copy link

gkatsanos commented Feb 2, 2021

can I over-write the built in reporters of nuxt core with a setting in the nuxt.config.js ?

@pi0
Copy link
Member Author

pi0 commented Feb 2, 2021

@gkatsanos You can set consola reporters in body of nuxt.config file. (nuxt/nuxt#8507 (comment))

Also respectfully, please use channels like nuxt discord to get help for your solutions such as datadog integration. I would also be more than happy if can help there. Sending random questions in several repo/issues is wasting time.

@pi0 pi0 closed this as completed in 091a244 Feb 2, 2021
@pi0
Copy link
Member Author

pi0 commented Feb 2, 2021

Issue fixed in v2.15.1

@gkatsanos You can get update with yarn upgrade nuxt (or better recreating lock file)

@gkatsanos
Copy link

@pi0 I think I need to wait until its propagated to the main repo, right? https://github.com/nuxt/nuxt.js/releases

@pi0
Copy link
Member Author

pi0 commented Feb 2, 2021

@gkatsanos nop npm magic! (nuxt has range dependency on consola like ^2.15.0) when lock file is created, it will fetch latest possible in range :)

@gkatsanos
Copy link

@pi0 would you be available on the Vue Discord ? ( console.error ( { .. } ) still generates invalid JSON)

@pi0
Copy link
Member Author

pi0 commented Feb 2, 2021

@gkatsanos Sure pi0#6582

@gkatsanos
Copy link

gkatsanos commented Feb 2, 2021

console.error when wrapped still adds ERROR in front of the object returned. reproduction: https://repl.it/@gkatsans/Consola-2#index.js
I guess this may be intended, in which case what would be the workaround? (also messaged you in Discord)

@pi0
Copy link
Member Author

pi0 commented Feb 2, 2021

It is intended indeed. Fancy reporter adds the badge. So you should either opt-out in nuxt or replace reporters

@gkatsanos
Copy link

Thanks. I can add a parser in Datadog that handles it but I guess going with the previous suggestion of

consola.setReporters([
  {
    log: (e) => {
      process.stdout.write(JSON.stringify(e))
    },
  },
])

in nuxt.config.js seems a more safe solution as I could also do further manipulation there centrally.. What do you think? (add a timestamp, structure the response etc)

@pi0
Copy link
Member Author

pi0 commented Feb 2, 2021

nuxt.config is safest place indeed (also please note consola should not be modified in other places. only use console.* calls)

nevilm-lt pushed a commit to nevilm-lt/consola that referenced this issue Apr 22, 2022
himanshiLt pushed a commit to himanshiLt/consola that referenced this issue Apr 28, 2022
nevilm-lt pushed a commit to nevilm-lt/consola that referenced this issue May 2, 2022
nevilm-lt pushed a commit to nevilm-lt/consola that referenced this issue May 2, 2022
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

2 participants