1
0
mirror of https://github.com/golang/go synced 2024-11-24 22:00:09 -07:00

exp/template: ensure that a valid Set is returned even on error.

R=r
CC=golang-dev
https://golang.org/cl/4838044
This commit is contained in:
Roger Peppe 2011-08-01 09:02:06 -07:00 committed by Rob Pike
parent 317911c9ff
commit 5c5ce6d24d

View File

@ -97,6 +97,7 @@ func (s *Set) ParseFile(filenames ...string) (*Set, os.Error) {
// named files. Each file must be individually parseable.
func ParseSetFile(filenames ...string) (*Set, os.Error) {
s := new(Set)
s.init()
for _, filename := range filenames {
b, err := ioutil.ReadFile(filename)
if err != nil {
@ -193,6 +194,7 @@ func (s *Set) ParseTemplateFiles(pattern string) (*Set, os.Error) {
// encountered.
func ParseTemplateFile(filenames ...string) (*Set, os.Error) {
set := new(Set)
set.init()
for _, filename := range filenames {
t, err := ParseFile(filename)
if err != nil {
@ -217,6 +219,7 @@ func ParseTemplateFile(filenames ...string) (*Set, os.Error) {
// encountered.
func ParseTemplateFiles(pattern string) (*Set, os.Error) {
set := new(Set)
set.init()
filenames, err := filepath.Glob(pattern)
if err != nil {
return set, err