Skip to content

proposal: text/template: add more details to ExecError #71801

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

Open
jessesimpson36 opened this issue Feb 17, 2025 · 1 comment
Open

proposal: text/template: add more details to ExecError #71801

jessesimpson36 opened this issue Feb 17, 2025 · 1 comment
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool Proposal
Milestone

Comments

@jessesimpson36
Copy link

jessesimpson36 commented Feb 17, 2025

Proposal Details

Hello all,

I would like to propose that the ExecError type found in text/template tracks more fields than just the name of the template and the error message which includes the template:

https://cs.opensource.google/go/go/+/refs/tags/go1.23.6:src/text/template/exec.go;l=114-147

I would like to propose that we introduce additional fields to include the location of the error (as in the line number and column number), a version of the error message string that does not include the template name, and the "context" (which means the executed function call). The proposed error type would look like the following:

type ExecError struct {
	Name string // Name of template.
+	LineNumber int // line location of the template that triggered the error
+	ColumnNumber int // column number pointing to the template that triggered the error
+	Context string // the name of the function call that triggered the error
+	ErrWithoutTemplate string // Just the error message, no template / context info
	Err  error  // Pre-formatted error.
}

The reason that I am proposing these changes to the struct is because I am helping out with a downstream repository helm (https://github.com/helm/helm). I want to introduce a change to improve their error message formats.
issue in helm: helm/helm#13447
PR to helm: helm/helm#13586

In my PR to helm, I found that I needed to introduce string manipulation logic to extract these fields that are already captured, but not saved, inside the text/template error state.

Does this proposal make sense?

Thanks

@gopherbot gopherbot added this to the Proposal milestone Feb 17, 2025
@gabyhelp gabyhelp added the LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool label Feb 17, 2025
@seankhliao seankhliao changed the title proposal: text/template: improve specificity of ExecError type proposal: text/template: add more details to ExecError Feb 17, 2025
@ianlancetaylor ianlancetaylor moved this to Incoming in Proposals Feb 17, 2025
@ianlancetaylor
Copy link
Member

CC @robpike

I note that the code has a related comment:

// TODO: It would be nice if ExecError was more broken down, but
// the way ErrorContext embeds the template name makes the
// processing too clumsy.

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 Proposal
Projects
Status: Incoming
Development

No branches or pull requests

4 participants