Closed mike76-dev closed 3 months ago
SetErr
is not allowing overwriting errors on purpose, because doing so might hide the root error causing an issue.
When dealing with versioning the ideal solution is usually storing/sending the version first and then continue decoding accordingly. If that is not possible, another approach is to first try and decode into the new type and if that fails try to decode into the old type. If the latter succeeds you know it was the old one. That's not as nice as the first approach but works usually.
I'm struggling with this code:
I'm writing a compat code where I'm reading a struct that may or may not contain a field. If it doesn't contain that field, I need to set
d.err
tonil
or a custom error that will indicate upstream that the compat code has executed. Currently this is not possible, because changing thed.err
value is only possible when it'snil
, but in my case it'sEOF
.