mobxjs / serializr

Serialize and deserialize complex object graphs to and from JSON and Javascript classes
MIT License
766 stars 52 forks source link

the error output should be more readable #62

Closed chengjianhua closed 5 years ago

chengjianhua commented 7 years ago

image

the stack trace:

https://github.com/mobxjs/serializr/blob/master/src/types/primitive.js#L20

https://github.com/mobxjs/serializr/blob/master/src/utils/utils.js#L19

invariant(isPrimitive(value), "this value is not primitive: " + value)

Can we JSON.stringify() or just place an statement console.log(nonPrimitiveValue) before invariant() throwing an error ?

Or is there any better solutions ? @alexggordon

alexggordon commented 7 years ago

Hmm, yes I'd agree. Error messages are rather cryptic in serializr. It would be good to improve the error messages across the board. Unfortunately, the way the invariant function works, it would require changing all the invariant calls to JSON.stringify the value before logging it. Let me do some investigation over the next day or two to see if I can improve the logging in a simpler way.

chengjianhua commented 7 years ago

@alexggordon Do you come up with a good idea about this ?

chengjianhua commented 7 years ago

@alexggordon

https://github.com/visionmedia/debug/blob/71169065b5262f9858ac78cc0b688c84a438f290/src/common.js#L102

https://github.com/visionmedia/debug/blob/71169065b5262f9858ac78cc0b688c84a438f290/src/browser.js#L183

We can brow the idea of debug which was used to output readable log message includes object and some other non-primitive data.

Implementing a simple utility that supports syntax like below:

invariant(
  false,
  'This is a object %o',
  { x: 1, y: 1 },
);
1R053 commented 5 years ago

closed with #68