tj / node-migrate

Abstract migration framework for node
MIT License
1.53k stars 221 forks source link

Better error logging #159

Open vuhrmeister opened 5 years ago

vuhrmeister commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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.