I created a variable in Go:
go
var UnexpectedEOFJSON = errors.New("unexpected end of JSON input")
This variable is intended to handle situations where a JSON input unexpectedly terminates. In my implementation, I retrieve a column that has the potential to be null. Consequently, when I attempt to unmarshal the JSON into the appropriate struct, I encounter an issue: if the []byte is empty, the unmarshalling process may trigger an "unexpected end of JSON input" error.
To address this, I introduced a conditional check:
if errors.Is(err, UnexpectedEOFJSON) {
// handle the error
}
However, this check consistently returns false, even though, when I output the error message, it explicitly states "unexpected end of JSON input". This discrepancy indicates that the error handling is not functioning as expected, and the condition designed to catch this specific error is not being met.