Open ConradIrwin opened 7 years ago
I don't think he is going to complete that cla, so I'm going to rework this so we can get it in.
This can be closed if #25 is merged.
fixed — sorry for missing that! Also happy for your version to be merged instead
Ah, no sweat. I didn't think you'd jump on it so quickly after two years, else I wouldn't have done that. Yeah, I hope you get merged up.
Suggestion: marshal to just the inner list, instead of wrapping it in an {"errors": }
object.
(Disclaimer: I'm not affiliated with Hashicorp in any way, I'm just a rando on the internet with Ideas(TM) and the hubris to think they're worth saying.)
Consider the difference between:
{ "response": null, "errors": [ "foo", "bar" ] }
{ "response": null, "errors": { "errors": [ "foo", "bar" ] } }
Basically:
don't we usually marshal data like a list of errors into a bigger surrounding JSON blob anyway?
isn't that surrounding context going to have its own "errors" key or other indicator that the data is a list of errors?
Without this change any objects containing a multierror will fail to Marshal, though most objects that implement the Error() interface are safe (albeit not useful) to convert to JSON.
This pull request goes one step further and tries to make the JSON output somewhat useful, and defines a way to reconstruct a multierror that looks superficially similar to the original when Unmarshalled again.