-
Notifications
You must be signed in to change notification settings - Fork 18k
encoding/xml: use typed error for "non-pointer passed to Unmarshal" #57557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
How about this? if err.Error() == "non-pointer passed to Unmarshal" { |
It also works but it's not considered the best practice to handle errors by using their string value. |
Generally it's useful to have a typed error for an error that can be caused by user input, where the program may need to take different action depending on what it sees. It's less clear that that's useful for a case like this where the only possible fix is to change the program. When would it be useful for a program to explicitly detect this case? What would it do when it happens? |
I would suggest the 500 response for any unrecognized error. Does it help to categorize this particular error? |
How many recongnized errors do we have? |
Sorry I accidentally deleted my reply to this comment, so I am writing it again. |
Indeed, and there's a |
I know there is |
@mojixcoder, I am a bit curious about why you need handle this error. could you please give some explanation?In my option, say that if you passed a non-pointer variable to the function, when you fix it, the error will never appear again. |
I've already said that: |
@mojixcoder Sorry. how about just returning the error to web framework user? just like Gin framework |
@jacobishao I'm returing error at the end but wanted to be able to return different errors. |
In the
encoding/xml
package when a non-pointer is passed to the function, it returns a new error witherrors.New
function.The problem is that we cannot handle errors like this:
encoding/json
returns*json.InvalidUnmarshalError
when a non-pointer is passed and it can be handled on the client side because it doesn't return the error witherrors.New
function.It happens in here:
go/src/encoding/xml/read.go
Line 150 in db36eca
The text was updated successfully, but these errors were encountered: