corectl icon indicating copy to clipboard operation
corectl copied to clipboard

Warn in case of information loss from Unmarshal

Open glooms opened this issue 6 years ago • 3 comments

Go's default json.Unmarshal disregards any information that could not be properly mapped to the provided container (struct/slice/map). If we are working with an engine version not compatible with our enigma version it is plausible we would get information loss which is dangerous in a version control or unbuild/build scenario.

We should at the very least warn the user if information loss has occurred.

glooms avatar Jul 11 '19 07:07 glooms

There seems to be an easy way to do this, but it has a couple of key limitations that might make it poorly suited for our case.

Using the builtin Decoder from encoding/json you can set DisallowUnknownFields() which will cause the decoder to return an error if there is data that is not mapped to the field of a struct. The drawback however is that it only returns the first unknown field, meaning we have no way of knowing how many such fields there are.

glooms avatar Jul 19 '19 11:07 glooms

It seems like this doesn't happen as this is the same as having unrecognized fields (if I'm not mistaken). I'll leave this open until clarification from @wennmo and @gabbaxx

glooms avatar Jul 22 '19 08:07 glooms

This will only be an issue while using the --minimum flag and under the specific circumstance that corectl uses a version of enigma that was generated for a QIX-api version older that of the engine which the user is using.

We could raise a warning, if this is the case.

glooms avatar Sep 02 '19 11:09 glooms