aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2009-05-13 10:01:55 -0700
committerRob Pike <r@golang.org>2009-05-13 10:01:55 -0700
commit52f071ed4318634a872e211aebf7d55ddd271bb4 (patch)
tree1a320e80d7428e567f93c93eda228afbe18c27bd /src
parent98b4f6ac3812b9114740af98447ddde6c8f100a1 (diff)
downloadgo-52f071ed4318634a872e211aebf7d55ddd271bb4.tar.xz
Rename ParseError to Error
R=rsc DELTA=13 (6 added, 1 deleted, 6 changed) OCL=28743 CL=28746
Diffstat (limited to 'src')
-rw-r--r--src/lib/template/template.go17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/lib/template/template.go b/src/lib/template/template.go
index f266e6014d..335a306901 100644
--- a/src/lib/template/template.go
+++ b/src/lib/template/template.go
@@ -57,6 +57,7 @@
package template
import (
+ "container/vector";
"fmt";
"io";
"os";
@@ -64,13 +65,17 @@ import (
"runtime";
"strings";
"template";
- "container/vector";
)
-// Errors returned during parsing. TODO: different error model for execution?
+// Errors returned during parsing and execution. Users may extract the information and reformat
+// if they desire.
+type Error struct {
+ Line int;
+ Msg string;
+}
-type ParseError struct {
- os.ErrorString
+func (e *Error) String() string {
+ return fmt.Sprintf("line %d: %s", e.Line, e.Msg)
}
// Most of the literals are aces.
@@ -181,7 +186,7 @@ func New(fmap FormatterMap) *Template {
// Generic error handler, called only from execError or parseError.
func error(errors chan os.Error, line int, err string, args ...) {
- errors <- ParseError{os.ErrorString(fmt.Sprintf("line %d: %s", line, fmt.Sprintf(err, args)))};
+ errors <- &Error{line, fmt.Sprintf(err, args)};
runtime.Goexit();
}
@@ -756,7 +761,7 @@ func validDelim(d []byte) bool {
// the error.
func (t *Template) Parse(s string) os.Error {
if !validDelim(t.ldelim) || !validDelim(t.rdelim) {
- return ParseError{os.ErrorString(fmt.Sprintf("bad delimiter strings %q %q", t.ldelim, t.rdelim))}
+ return &Error{1, fmt.Sprintf("bad delimiter strings %q %q", t.ldelim, t.rdelim)}
}
t.buf = io.StringBytes(s);
t.p = 0;