You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is currently not an easy way to test for missing key error from text/template in the case that that the template was constructed with the missingkey=error option.
I propose adding a new error type in text/template testable via errors.As and the missing key can be recovered:
This would be added in a way that doesn't cause the existing error's string representation to change, allowing any users that might be checking for certain sub-string in the error strings to gracefully transition to the new way.
Edit: changed fmt.Errorf to errors.New
Edit: took suggestion from @icholy to have the error be a struct type, allowing users to be able to recover the offending key.
The text was updated successfully, but these errors were encountered:
seankhliao
changed the title
proposal: text/template: make it easier to discover missing key error
proposal: text/template: export error value for missingkey
Jan 15, 2023
seankhliao
changed the title
proposal: text/template: export error value for missingkey
proposal: text/template: export error type for missingkey
Jan 18, 2023
Can you show an example on programmatically detecting whether the cause for an ExecError is due to missing keys? I don't think that capability exists today unless you resort to sub-string checks against the error string, which isn't a reliable method.
There is currently not an easy way to test for missing key error from
text/template
in the case that that the template was constructed with themissingkey=error
option.I propose adding a new error type in
text/template
testable viaerrors.As
and the missing key can be recovered:This would be added in a way that doesn't cause the existing error's string representation to change, allowing any users that might be checking for certain sub-string in the error strings to gracefully transition to the new way.
Edit: changed
fmt.Errorf
toerrors.New
Edit: took suggestion from @icholy to have the error be a struct type, allowing users to be able to recover the offending key.
The text was updated successfully, but these errors were encountered: