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

Better error logging #159

Open
vuhrmeister opened this issue Jun 11, 2019 · 4 comments
Open

Better error logging #159

vuhrmeister opened this issue Jun 11, 2019 · 4 comments

Comments

@vuhrmeister
Copy link

I'm writing my own store class. Inside save or load on exceptions I call fn(error). But if error is a plain Object then only this is being logged.

  error : [object Object]

The problem is, that the error is logged as a string: https://github.com/tj/node-migrate/blob/master/lib/log.js#L9

I would rather change it to something like this, thus making it more general:

module.exports.error = function log (key, msg) {
  console.error('  ' + chalk.red(key) + ' : ', msg)
}
@wesleytodd
Copy link
Collaborator

Hi @vuhrmeister, while I agree the logging is not great, I don't think we will change this until the next major. When we do that, I plan on having a whole lot more robust solution for logging. In the mean time, why not log an error instance? That way your error message would be logged properly.

@vuhrmeister
Copy link
Author

Well, I can do that. It's just that the api I'm using is only returning an Object as error So I would always need to wrap it. Not the prettiest code then.

@vuhrmeister
Copy link
Author

btw: just wrapping an object with an Error doesn't change anything. A standard error also just excepts a string and prints Error: [object Object] otherwise. The only additional information I get is the stack trace.

@wesleytodd
Copy link
Collaborator

Hey, I mean an object is not an error. I am not sure this lib can solve this problem for you, and even my future logging efforts will require it to be a real Error instance. I am guessing your object has some message in it, so something like new Error(obj.message) would do the trick. Good luck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants