-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
What version of Go are you using (go version
)?
go1.11 windows/amd64
Problem
When an error is thrown because a template is missing a value ("missingkey=error"
), the error sent will truncate the context upon which the field is evaluated.
executing "someTemplateName" at <.k8s.clusters.someCl...>: map has no entry for key "someField"
Sample code to demontrate : https://play.golang.org/p/h3_fgkbUo_S
This is where the string gets truncated :
go/src/text/template/parse/parse.go
Line 151 in 7dda512
if len(context) > 20 { |
Why is that a problem
I'm pretty sure this has been met by many users using tools that use the text/template
engine (hello helm users). Once the context is deep enough, it become excitedly difficult to understand where in the data tree something is missing. If the field is dynamically accessed, say through a variable, it become pretty much impossible to know what exactly is wrong and how to fix the template.
My particular use case is that i'm trying to list all accessed values in a template, since it is impossible to access the internal structure of the parse.Tree, i though i could execute a template, catch missing value errors and construct a list through error messages.
Proposal for a solution
There are multiple solutions
- add more specific error (parse.ValueNotFound ?) which give detailed informations which include the context
- modify func ErrorContext to remove truncation
- enable some option to keep the behavior backward compatible