diff options
author | Rob Pike <r@golang.org> | 2014-05-19 14:29:45 -0700 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2014-05-19 14:29:45 -0700 |
commit | 431b96bdbe7dc838551efc9959b3bdca780b9368 (patch) | |
tree | f9cf8c4d9a451d4a7fa2a4a4a12d1d5e558527c1 | |
parent | a663e0a0381c22d3b1ef58b411df5cfbf56c2930 (diff) | |
download | go-431b96bdbe7dc838551efc9959b3bdca780b9368.tar.gz go-431b96bdbe7dc838551efc9959b3bdca780b9368.zip |
text/template,html/template: document that partial results may be written on error
Fixes #7445.
LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/94640043
-rw-r--r-- | src/pkg/html/template/template.go | 6 | ||||
-rw-r--r-- | src/pkg/text/template/exec.go | 6 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/pkg/html/template/template.go b/src/pkg/html/template/template.go index 744f139ba4..d389658979 100644 --- a/src/pkg/html/template/template.go +++ b/src/pkg/html/template/template.go @@ -62,6 +62,9 @@ func (t *Template) escape() error { // Execute applies a parsed template to the specified data object, // writing the output to wr. +// If an error occurs executing the template or writing its output, +// execution stops, but partial results may already have been written to +// the output writer. // A template may be executed safely in parallel. func (t *Template) Execute(wr io.Writer, data interface{}) error { if err := t.escape(); err != nil { @@ -72,6 +75,9 @@ func (t *Template) Execute(wr io.Writer, data interface{}) error { // ExecuteTemplate applies the template associated with t that has the given // name to the specified data object and writes the output to wr. +// If an error occurs executing the template or writing its output, +// execution stops, but partial results may already have been written to +// the output writer. // A template may be executed safely in parallel. func (t *Template) ExecuteTemplate(wr io.Writer, name string, data interface{}) error { tmpl, err := t.lookupAndEscapeTemplate(name) diff --git a/src/pkg/text/template/exec.go b/src/pkg/text/template/exec.go index 505509a085..2f32312645 100644 --- a/src/pkg/text/template/exec.go +++ b/src/pkg/text/template/exec.go @@ -108,6 +108,9 @@ func errRecover(errp *error) { // ExecuteTemplate applies the template associated with t that has the given name // to the specified data object and writes the output to wr. +// If an error occurs executing the template or writing its output, +// execution stops, but partial results may already have been written to +// the output writer. // A template may be executed safely in parallel. func (t *Template) ExecuteTemplate(wr io.Writer, name string, data interface{}) error { tmpl := t.tmpl[name] @@ -119,6 +122,9 @@ func (t *Template) ExecuteTemplate(wr io.Writer, name string, data interface{}) // Execute applies a parsed template to the specified data object, // and writes the output to wr. +// If an error occurs executing the template or writing its output, +// execution stops, but partial results may already have been written to +// the output writer. // A template may be executed safely in parallel. func (t *Template) Execute(wr io.Writer, data interface{}) (err error) { defer errRecover(&err) |