You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I setup a reader that expects 2 fields per record and gave it some data with only 1 field. The csv.Reader returns a *csv.ParseError that contians the details about not containing enough fields.
When comparing against an empty *csv.ParseError, errors.Is() returns false and errors.As() returns true.
What did you expect to see?
I had the understanding that errors.Is and errors.As would return the same bool values when passed similar parameters indicating that the error is of that type. Either both would return true or both would return false. In this setup, I expected errors.Is(err, &csv.ParseError{}) to return true because the error is indeed a *csv.ParseError.
What did you see instead?
Instead, I find that errors.Is() returns false and errors.As() returns true when given similar parameters.
The text was updated successfully, but these errors were encountered:
coreyog
changed the title
For *csv.ParseError, error.Is() comes back false and error.As() comes back true?
For *csv.ParseError, error.Is() comes back false and error.As() comes back true?
Oct 15, 2020
errors.Is and errors.As are different. Your example using errors.Is is basically asking "is the returned error an empty csv.ParseError? The answer is no; it is not an empty csv.ParseError, it is a csv.ParseError that includes some data. Your example using errors.As is saying: "give me this error in the form of a csv.ParseError", and that is what happens.
errors.Is is like ==, errors.As is like a type assertion.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://play.golang.org/p/SdpH9lJMVu1
I setup a reader that expects 2 fields per record and gave it some data with only 1 field. The csv.Reader returns a
*csv.ParseError
that contians the details about not containing enough fields.When comparing against an empty
*csv.ParseError
,errors.Is()
returns false anderrors.As()
returns true.What did you expect to see?
I had the understanding that
errors.Is
anderrors.As
would return the same bool values when passed similar parameters indicating that the error is of that type. Either both would return true or both would return false. In this setup, I expectederrors.Is(err, &csv.ParseError{})
to return true because the error is indeed a*csv.ParseError
.What did you see instead?
Instead, I find that
errors.Is()
returns false anderrors.As()
returns true when given similar parameters.The text was updated successfully, but these errors were encountered: