-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Open
Description
The proposal is to add options like error=zero, error=default in a likewise fashion as in missingkey=....
The intention is to let users specify how function calls inside templates should be handled. In a template pipeline with functions (or methods) calls with 2 returns, a value and an error, execution stops if the error is not nil. I think it would be useful if the user could specify how to proceed. So passing options seems to be a natural way. For example:
- the option
error=defaultkeeps the same behavior: stop execution error=zerosets the returned value to be the zero value for that type and keeps executingerror=errorvaluesets the returned value to be the error and keeps executing
Of course the key name could be different I just used error here to clarify. Implementing this would make error handling in templates possible, thus making it much more powerful. E.g.:
// Run function returns (string, error)
{{with .Run}}
{{if .}}
no error case with error=zero or error value with error=errorvalue
run is {{.}}
{{else}}
error case, . is empty string on option `error=zero`
{{end}}
{{end}}
Thanks!
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Incoming