proposal: cmd/vet: diagnose marshal of field of type error #45108
This proposal is to add a new vet checker that warns when an exported
This behavior is well defined, but many users expect to see the "err.Error()" value. These would consider their code buggy. So this plausibly satisfies vet's correctness criteria.
The current focus is on
To avoid spurious reports the proposed conditions to warn would be when:
These reports can potentially be considered false positives when all of the underlying types of the error values stored in the field have an MarshalJSON function defined or have a well defined serialization:
This would not report flows through
The text was updated successfully, but these errors were encountered:
The hard part here is false positives. It is technically fine to json.Marshal a field of type error when it is nil or when it contains a JSON-able error. If you only trigger when you know it's a non-JSON-able error, that would be a possibility. But that might have too many false negatives.