Content-Length: 260929 | pFad | http://github.com/golang/go/issues/71421

63 text/template: improve error message "incompatible types for comparison" · Issue #71421 · golang/go · GitHub
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

text/template: improve error message "incompatible types for comparison" #71421

Open
jdemeyer opened this issue Jan 24, 2025 · 3 comments
Open
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@jdemeyer
Copy link

Go version

go version go1.23.5 linux/amd64

Output of go env in your module/workspace:

GO111MODULE='on'
GOARCH='amd64'
GOBIN='/home/jdemeyer/.local/bin'
GOCACHE='/home/jdemeyer/.cache/go-build'
GOENV='/home/jdemeyer/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/jdemeyer/go/pkg/mod'
GONOPROXY='bitbucket.org/be-mobile'
GONOSUMDB='bitbucket.org/be-mobile'
GOOS='linux'
GOPATH='/home/jdemeyer/go'
GOPRIVATE='bitbucket.org/be-mobile'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/snap/go/10818'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/snap/go/10818/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.5'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/jdemeyer/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v3'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1587861785=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Actually, this problem came via using helm to template a Helm chart, but this is the essence of the problem in pure Go:

package main

import (
	"io"
	"text/template"
)

func main() {
	const tmpl = "{{ gt .a .b }}"
	var t = template.Must(template.New("test").Parse(tmpl))
	args := map[string]any{
		"a": 1.0,  // Intentionally incomparable types
		"b": 2,
	}
	err := t.Execute(io.Discard, args)
	if err != nil {
		panic(err)
	}
}

What did you see happen?

panic: template: test:1:3: executing "test" at <gt .a .b>: error calling gt: incompatible types for comparison

What did you expect to see?

panic: template: test:1:3: executing "test" at <gt .a .b>: error calling gt: incompatible types for comparison: float64, int

It would be helpful to add in the error message which types are causing the incompatibility. When using text/template in Helm, there are many layers in between, so the error message incompatible types for comparison might not be easy to debug.

@gabyhelp gabyhelp added the LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool label Jan 24, 2025
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/644175 mentions this issue: text/template improved comparison error addresses issue #71421

@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 27, 2025
@cagedmantis cagedmantis added this to the Backlog milestone Jan 27, 2025
@cagedmantis
Copy link
Contributor

cc @robpike @mvdan

gopherbot pushed a commit that referenced this issue Feb 3, 2025
Addresses issue #71421, improves the error message given for comparison. Previous error message did not specify the types causing conflict, just said incompatible types, new error message specifies the two types causing the issue.

Change-Id: I9d940ab7573c2763a9d052445140ecd6d38cde5e
GitHub-Last-Rev: 6fe7d81
GitHub-Pull-Request: #71431
Reviewed-on: https://go-review.googlesource.com/c/go/+/644175
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Rob Pike <r@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/golang/go/issues/71421

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy