zertosh / invariant

invariant
MIT License
1.22k stars 70 forks source link

what is the best practice for displaying plain objects in error messages? #8

Closed greaber closed 9 years ago

greaber commented 9 years ago

I started using this module but noticed that if an object has the default toString method and I pass it in a %s specifier, it gets printed using the default object toString method, which gives the unhelpful string "[object Object]". I would prefer that the printing used util.inspect or something. How do users of invariant typically deal with this issue?

zertosh commented 9 years ago

Yeah using something like util.inspect would def provide more info, but that's not really the point of this library. It's not meant to be a full assertion lib. It's a supposed to be small and light - with the benefit of enforcing the message requirement in production.

greaber commented 9 years ago

OK, maybe I should be using something else then. But I don't get really get what the niche for invariant is supposed to be in this case. If you are going to log an error message at all, why would you want to log one that lacks information? You say invariant is meant to be small and light, but the download and parsing time and memory usage of something like util.inspect should be negligible, right?

zertosh commented 9 years ago

The log captures primitives perfectly fine. This isn't a logger. Also, for the most part, consumers of this library strip away messages at release time.

greaber commented 9 years ago

Right, I wasn't saying anything about whether messages should or should not be stripped away at release time, just that in any environment where they are not stripped you may as well have good logging of objects as well as primitives. Anyway, I will close the issue since the library is what it is.