diff options
| author | Russ Cox <rsc@golang.org> | 2011-11-01 22:05:34 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2011-11-01 22:05:34 -0400 |
| commit | eb6929299b6da3d9bea1fa7f7cd319c2de9242bb (patch) | |
| tree | d3309a8985202985334709bc50e1a737ea117593 /src/pkg/template | |
| parent | c2049d2dfeeea3d41fafa91e3e3f0e47c285355b (diff) | |
| download | go-eb6929299b6da3d9bea1fa7f7cd319c2de9242bb.tar.xz | |
src/pkg/[n-z]*: gofix -r error -force=error
R=golang-dev, bsiegert, iant
CC=golang-dev
https://golang.org/cl/5294074
Diffstat (limited to 'src/pkg/template')
| -rw-r--r-- | src/pkg/template/exec.go | 13 | ||||
| -rw-r--r-- | src/pkg/template/exec_test.go | 4 | ||||
| -rw-r--r-- | src/pkg/template/funcs.go | 5 | ||||
| -rw-r--r-- | src/pkg/template/helper.go | 29 | ||||
| -rw-r--r-- | src/pkg/template/parse.go | 5 | ||||
| -rw-r--r-- | src/pkg/template/parse/node.go | 3 | ||||
| -rw-r--r-- | src/pkg/template/parse/parse.go | 9 | ||||
| -rw-r--r-- | src/pkg/template/parse/set.go | 3 | ||||
| -rw-r--r-- | src/pkg/template/set.go | 7 |
9 files changed, 35 insertions, 43 deletions
diff --git a/src/pkg/template/exec.go b/src/pkg/template/exec.go index 34c6633232..7850f6daf5 100644 --- a/src/pkg/template/exec.go +++ b/src/pkg/template/exec.go @@ -7,7 +7,6 @@ package template import ( "fmt" "io" - "os" "reflect" "runtime" "strings" @@ -70,25 +69,25 @@ func (s *state) errorf(format string, args ...interface{}) { } // error terminates processing. -func (s *state) error(err os.Error) { +func (s *state) error(err error) { s.errorf("%s", err) } // errRecover is the handler that turns panics into returns from the top // level of Parse. -func errRecover(errp *os.Error) { +func errRecover(errp *error) { e := recover() if e != nil { if _, ok := e.(runtime.Error); ok { panic(e) } - *errp = e.(os.Error) + *errp = e.(error) } } // Execute applies a parsed template to the specified data object, // writing the output to wr. -func (t *Template) Execute(wr io.Writer, data interface{}) (err os.Error) { +func (t *Template) Execute(wr io.Writer, data interface{}) (err error) { defer errRecover(&err) value := reflect.ValueOf(data) state := &state{ @@ -446,7 +445,7 @@ func methodByName(receiver reflect.Value, name string) (reflect.Value, bool) { } var ( - osErrorType = reflect.TypeOf((*os.Error)(nil)).Elem() + osErrorType = reflect.TypeOf((*error)(nil)).Elem() fmtStringerType = reflect.TypeOf((*fmt.Stringer)(nil)).Elem() ) @@ -495,7 +494,7 @@ func (s *state) evalCall(dot, fun reflect.Value, name string, args []parse.Node, result := fun.Call(argv) // If we have an os.Error that is not nil, stop execution and return that error to the caller. if len(result) == 2 && !result[1].IsNil() { - s.errorf("error calling %s: %s", name, result[1].Interface().(os.Error)) + s.errorf("error calling %s: %s", name, result[1].Interface().(error)) } return result[0] } diff --git a/src/pkg/template/exec_test.go b/src/pkg/template/exec_test.go index 2d2b402942..20839c3e34 100644 --- a/src/pkg/template/exec_test.go +++ b/src/pkg/template/exec_test.go @@ -159,7 +159,7 @@ func (t *T) MSort(m map[string]int) []string { } // EPERM returns a value and an os.Error according to its argument. -func (t *T) EPERM(error bool) (bool, os.Error) { +func (t *T) EPERM(error bool) (bool, error) { if error { return true, os.EPERM } @@ -548,7 +548,7 @@ func TestExecuteError(t *testing.T) { err = tmpl.Execute(b, tVal) if err == nil { t.Errorf("expected error; got none") - } else if !strings.Contains(err.String(), os.EPERM.String()) { + } else if !strings.Contains(err.Error(), os.EPERM.Error()) { if *debug { fmt.Printf("test execute error: %s\n", err) } diff --git a/src/pkg/template/funcs.go b/src/pkg/template/funcs.go index 938559eec9..59c2ee708c 100644 --- a/src/pkg/template/funcs.go +++ b/src/pkg/template/funcs.go @@ -8,7 +8,6 @@ import ( "bytes" "fmt" "io" - "os" "reflect" "strings" "unicode" @@ -102,7 +101,7 @@ func findFunction(name string, tmpl *Template, set *Set) (reflect.Value, bool) { // index returns the result of indexing its first argument by the following // arguments. Thus "index x 1 2 3" is, in Go syntax, x[1][2][3]. Each // indexed item must be a map, slice, or array. -func index(item interface{}, indices ...interface{}) (interface{}, os.Error) { +func index(item interface{}, indices ...interface{}) (interface{}, error) { v := reflect.ValueOf(item) for _, i := range indices { index := reflect.ValueOf(i) @@ -144,7 +143,7 @@ func index(item interface{}, indices ...interface{}) (interface{}, os.Error) { // Length // length returns the length of the item, with an error if it has no defined length. -func length(item interface{}) (int, os.Error) { +func length(item interface{}) (int, error) { v, isNil := indirect(reflect.ValueOf(item)) if isNil { return 0, fmt.Errorf("len of nil pointer") diff --git a/src/pkg/template/helper.go b/src/pkg/template/helper.go index 1dc90f7ff4..b7a9deeba9 100644 --- a/src/pkg/template/helper.go +++ b/src/pkg/template/helper.go @@ -9,7 +9,6 @@ package template import ( "fmt" "io/ioutil" - "os" "path/filepath" ) @@ -19,7 +18,7 @@ import ( // and panics if the error is non-nil. It is intended for use in variable initializations // such as // var t = template.Must(template.New("name").Parse("text")) -func Must(t *Template, err os.Error) *Template { +func Must(t *Template, err error) *Template { if err != nil { panic(err) } @@ -28,7 +27,7 @@ func Must(t *Template, err os.Error) *Template { // ParseFile creates a new Template and parses the template definition from // the named file. The template name is the base name of the file. -func ParseFile(filename string) (*Template, os.Error) { +func ParseFile(filename string) (*Template, error) { t := New(filepath.Base(filename)) return t.ParseFile(filename) } @@ -37,7 +36,7 @@ func ParseFile(filename string) (*Template, os.Error) { // definition from the named file. The template name is the base name // of the file. It also adds the template to the set. Function bindings are // checked against those in the set. -func parseFileInSet(filename string, set *Set) (*Template, os.Error) { +func parseFileInSet(filename string, set *Set) (*Template, error) { t := New(filepath.Base(filename)) return t.parseFileInSet(filename, set) } @@ -45,7 +44,7 @@ func parseFileInSet(filename string, set *Set) (*Template, os.Error) { // ParseFile reads the template definition from a file and parses it to // construct an internal representation of the template for execution. // The returned template will be nil if an error occurs. -func (t *Template) ParseFile(filename string) (*Template, os.Error) { +func (t *Template) ParseFile(filename string) (*Template, error) { b, err := ioutil.ReadFile(filename) if err != nil { return nil, err @@ -57,7 +56,7 @@ func (t *Template) ParseFile(filename string) (*Template, os.Error) { // are checked against those in the set and the template is added // to the set. // The returned template will be nil if an error occurs. -func (t *Template) parseFileInSet(filename string, set *Set) (*Template, os.Error) { +func (t *Template) parseFileInSet(filename string, set *Set) (*Template, error) { b, err := ioutil.ReadFile(filename) if err != nil { return nil, err @@ -71,7 +70,7 @@ func (t *Template) parseFileInSet(filename string, set *Set) (*Template, os.Erro // and panics if the error is non-nil. It is intended for use in variable initializations // such as // var s = template.SetMust(template.ParseSetFiles("file")) -func SetMust(s *Set, err os.Error) *Set { +func SetMust(s *Set, err error) *Set { if err != nil { panic(err) } @@ -81,7 +80,7 @@ func SetMust(s *Set, err os.Error) *Set { // ParseFiles parses the named files into a set of named templates. // Each file must be parseable by itself. // If an error occurs, parsing stops and the returned set is nil. -func (s *Set) ParseFiles(filenames ...string) (*Set, os.Error) { +func (s *Set) ParseFiles(filenames ...string) (*Set, error) { for _, filename := range filenames { b, err := ioutil.ReadFile(filename) if err != nil { @@ -97,7 +96,7 @@ func (s *Set) ParseFiles(filenames ...string) (*Set, os.Error) { // ParseSetFiles creates a new Set and parses the set definition from the // named files. Each file must be individually parseable. -func ParseSetFiles(filenames ...string) (*Set, os.Error) { +func ParseSetFiles(filenames ...string) (*Set, error) { s := new(Set) for _, filename := range filenames { b, err := ioutil.ReadFile(filename) @@ -116,7 +115,7 @@ func ParseSetFiles(filenames ...string) (*Set, os.Error) { // pattern. The pattern is processed by filepath.Glob and must match at // least one file. // If an error occurs, parsing stops and the returned set is nil. -func (s *Set) ParseGlob(pattern string) (*Set, os.Error) { +func (s *Set) ParseGlob(pattern string) (*Set, error) { filenames, err := filepath.Glob(pattern) if err != nil { return nil, err @@ -130,7 +129,7 @@ func (s *Set) ParseGlob(pattern string) (*Set, os.Error) { // ParseSetGlob creates a new Set and parses the set definition from the // files identified by the pattern. The pattern is processed by filepath.Glob // and must match at least one file. -func ParseSetGlob(pattern string) (*Set, os.Error) { +func ParseSetGlob(pattern string) (*Set, error) { set, err := new(Set).ParseGlob(pattern) if err != nil { return nil, err @@ -150,7 +149,7 @@ func ParseSetGlob(pattern string) (*Set, os.Error) { // individual templates, which are then added to the set. // Each file must be parseable by itself. // If an error occurs, parsing stops and the returned set is nil. -func (s *Set) ParseTemplateFiles(filenames ...string) (*Set, os.Error) { +func (s *Set) ParseTemplateFiles(filenames ...string) (*Set, error) { for _, filename := range filenames { _, err := parseFileInSet(filename, s) if err != nil { @@ -170,7 +169,7 @@ func (s *Set) ParseTemplateFiles(filenames ...string) (*Set, os.Error) { // individual templates, which are then added to the set. // Each file must be parseable by itself. // If an error occurs, parsing stops and the returned set is nil. -func (s *Set) ParseTemplateGlob(pattern string) (*Set, os.Error) { +func (s *Set) ParseTemplateGlob(pattern string) (*Set, error) { filenames, err := filepath.Glob(pattern) if err != nil { return nil, err @@ -194,7 +193,7 @@ func (s *Set) ParseTemplateGlob(pattern string) (*Set, os.Error) { // individual templates, which are then added to the set. // Each file must be parseable by itself. Parsing stops if an error is // encountered. -func ParseTemplateFiles(filenames ...string) (*Set, os.Error) { +func ParseTemplateFiles(filenames ...string) (*Set, error) { set := new(Set) set.init() for _, filename := range filenames { @@ -220,7 +219,7 @@ func ParseTemplateFiles(filenames ...string) (*Set, os.Error) { // individual templates, which are then added to the set. // Each file must be parseable by itself. Parsing stops if an error is // encountered. -func ParseTemplateGlob(pattern string) (*Set, os.Error) { +func ParseTemplateGlob(pattern string) (*Set, error) { set := new(Set) filenames, err := filepath.Glob(pattern) if err != nil { diff --git a/src/pkg/template/parse.go b/src/pkg/template/parse.go index 3068a77bed..2fbd37ffa9 100644 --- a/src/pkg/template/parse.go +++ b/src/pkg/template/parse.go @@ -5,7 +5,6 @@ package template import ( - "os" "reflect" "template/parse" ) @@ -62,7 +61,7 @@ func (t *Template) Funcs(funcMap FuncMap) *Template { // Parse parses the template definition string to construct an internal // representation of the template for execution. -func (t *Template) Parse(s string) (tmpl *Template, err os.Error) { +func (t *Template) Parse(s string) (tmpl *Template, err error) { t.Tree, err = parse.New(t.name).Parse(s, t.leftDelim, t.rightDelim, t.parseFuncs, builtins) if err != nil { return nil, err @@ -74,7 +73,7 @@ func (t *Template) Parse(s string) (tmpl *Template, err os.Error) { // representation of the template for execution. It also adds the template // to the set. // Function bindings are checked against those in the set. -func (t *Template) ParseInSet(s string, set *Set) (tmpl *Template, err os.Error) { +func (t *Template) ParseInSet(s string, set *Set) (tmpl *Template, err error) { var setFuncs FuncMap if set != nil { setFuncs = set.parseFuncs diff --git a/src/pkg/template/parse/node.go b/src/pkg/template/parse/node.go index 7411327a65..a4e5514768 100644 --- a/src/pkg/template/parse/node.go +++ b/src/pkg/template/parse/node.go @@ -9,7 +9,6 @@ package parse import ( "bytes" "fmt" - "os" "strconv" "strings" ) @@ -239,7 +238,7 @@ type NumberNode struct { Text string // The original textual representation from the input. } -func newNumber(text string, typ itemType) (*NumberNode, os.Error) { +func newNumber(text string, typ itemType) (*NumberNode, error) { n := &NumberNode{NodeType: NodeNumber, Text: text} switch typ { case itemCharConstant: diff --git a/src/pkg/template/parse/parse.go b/src/pkg/template/parse/parse.go index 9934d8221d..1b6ab3af4f 100644 --- a/src/pkg/template/parse/parse.go +++ b/src/pkg/template/parse/parse.go @@ -8,7 +8,6 @@ package parse import ( "fmt" - "os" "runtime" "strconv" "unicode" @@ -75,7 +74,7 @@ func (t *Tree) errorf(format string, args ...interface{}) { } // error terminates processing. -func (t *Tree) error(err os.Error) { +func (t *Tree) error(err error) { t.errorf("%s", err) } @@ -94,7 +93,7 @@ func (t *Tree) unexpected(token item, context string) { } // recover is the handler that turns panics into returns from the top level of Parse. -func (t *Tree) recover(errp *os.Error) { +func (t *Tree) recover(errp *error) { e := recover() if e != nil { if _, ok := e.(runtime.Error); ok { @@ -103,7 +102,7 @@ func (t *Tree) recover(errp *os.Error) { if t != nil { t.stopParse() } - *errp = e.(os.Error) + *errp = e.(error) } return } @@ -147,7 +146,7 @@ func (t *Tree) atEOF() bool { // Parse parses the template definition string to construct an internal // representation of the template for execution. If either action delimiter // string is empty, the default ("{{" or "}}") is used. -func (t *Tree) Parse(s, leftDelim, rightDelim string, funcs ...map[string]interface{}) (tree *Tree, err os.Error) { +func (t *Tree) Parse(s, leftDelim, rightDelim string, funcs ...map[string]interface{}) (tree *Tree, err error) { defer t.recover(&err) t.startParse(funcs, lex(t.Name, s, leftDelim, rightDelim)) t.parse(true) diff --git a/src/pkg/template/parse/set.go b/src/pkg/template/parse/set.go index b909f71cd7..d363eeff08 100644 --- a/src/pkg/template/parse/set.go +++ b/src/pkg/template/parse/set.go @@ -6,14 +6,13 @@ package parse import ( "fmt" - "os" "strconv" ) // Set returns a slice of Trees created by parsing the template set // definition in the argument string. If an error is encountered, // parsing stops and an empty slice is returned with the error. -func Set(text, leftDelim, rightDelim string, funcs ...map[string]interface{}) (tree map[string]*Tree, err os.Error) { +func Set(text, leftDelim, rightDelim string, funcs ...map[string]interface{}) (tree map[string]*Tree, err error) { tree = make(map[string]*Tree) defer (*Tree)(nil).recover(&err) lex := lex("set", text, leftDelim, rightDelim) diff --git a/src/pkg/template/set.go b/src/pkg/template/set.go index 712961b731..bd0dfc6b36 100644 --- a/src/pkg/template/set.go +++ b/src/pkg/template/set.go @@ -7,7 +7,6 @@ package template import ( "fmt" "io" - "os" "reflect" "template/parse" ) @@ -66,7 +65,7 @@ func (s *Set) Add(templates ...*Template) *Set { } // add adds the argument template to the set. -func (s *Set) add(t *Template) os.Error { +func (s *Set) add(t *Template) error { s.init() if t.set != nil { return fmt.Errorf("template: %q already in a set", t.name) @@ -92,7 +91,7 @@ func (s *Set) FuncMap() FuncMap { // Execute applies the named template to the specified data object, writing // the output to wr. -func (s *Set) Execute(wr io.Writer, name string, data interface{}) os.Error { +func (s *Set) Execute(wr io.Writer, name string, data interface{}) error { tmpl := s.tmpl[name] if tmpl == nil { return fmt.Errorf("template: no template %q in set", name) @@ -104,7 +103,7 @@ func (s *Set) Execute(wr io.Writer, name string, data interface{}) os.Error { // multiple times for a given set, adding the templates defined in the string // to the set. If a template is redefined, the element in the set is // overwritten with the new definition. -func (s *Set) Parse(text string) (*Set, os.Error) { +func (s *Set) Parse(text string) (*Set, error) { trees, err := parse.Set(text, s.leftDelim, s.rightDelim, s.parseFuncs, builtins) if err != nil { return nil, err |
