Skip to content
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

Error comparisons in templates not working until 1.14 #39108

Closed
timlind opened this issue May 16, 2020 · 3 comments
Closed

Error comparisons in templates not working until 1.14 #39108

timlind opened this issue May 16, 2020 · 3 comments

Comments

@timlind
Copy link

@timlind timlind commented May 16, 2020

What version of Go are you using (go version)?

$ go version
1.13

Does this issue reproduce with the latest release?

No.

What operating system and processor architecture are you using (go env)?

This is erroring on google app engine 1.13 and locally on 1.13, but not on 1.14

go env Output
$ go env

What did you do?

data := struct{
   Errors []error
   KnownErrors map[string]error
}{
   []error{ErrEmailExists},
   map[string]error{ErrEmailExists}
}

template.Execute(w, data)

{{range .Errors}}
{{if eq . $.KnownErrors.ErrEmailExists}}
Already registered.
{{end}}
{{end}}

What did you expect to see?

Already registered.

What did you see instead?

error calling eq: invalid type for comparison

@ALTree
Copy link
Member

@ALTree ALTree commented May 16, 2020

This is expected. A proposal to make eq support all comparable types (#33740) was accepted -and the fix merged- for Go1.14. So it won't work in go1.13, but it does on 1.14.

I don't think the change qualifies for a backport (we only backport fixes for serious security issues or problems with no workaround), so I'm not sure there's anything else left to do. I'm closing this issue as Working As Intended, but feel free to comment if you disagree.

@ALTree ALTree closed this May 16, 2020
@timlind
Copy link
Author

@timlind timlind commented May 16, 2020

Maybe some pointers to a workaround if there is one? Even trying to call and compare Error seemed to fail.

@timlind
Copy link
Author

@timlind timlind commented May 16, 2020

Ok, just tried it out on a playground and .Error comparisons work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.