exp/template/html: moved error docs out of package docs onto error codes
This replaces the errStr & errLine members of context with a single err
*Error, and introduces a number of const error codes, one per
escape-time failure mode, that can be separately documented.
The changes to the error documentation moved from doc.go to error.go
are cosmetic.
http://codereview.appspot.com/5026041/diff/5001/src/pkg/exp/template/html/error.go File src/pkg/exp/template/html/error.go (right): http://codereview.appspot.com/5026041/diff/5001/src/pkg/exp/template/html/error.go#newcode35 src/pkg/exp/template/html/error.go:35: // it from filtering. i filed a bug with ...
12 years, 8 months ago
(2011-09-15 01:03:45 UTC)
#2
http://codereview.appspot.com/5026041/diff/5001/src/pkg/exp/template/html/error.go File src/pkg/exp/template/html/error.go (right): http://codereview.appspot.com/5026041/diff/5001/src/pkg/exp/template/html/error.go#newcode105 src/pkg/exp/template/html/error.go:105: ErrBranchEnd os.Error ack! yes. i missed this, conflating these ...
12 years, 8 months ago
(2011-09-15 01:43:11 UTC)
#4
http://codereview.appspot.com/5026041/diff/5001/src/pkg/exp/template/html/err...
File src/pkg/exp/template/html/error.go (right):
http://codereview.appspot.com/5026041/diff/5001/src/pkg/exp/template/html/err...
src/pkg/exp/template/html/error.go:105: ErrBranchEnd os.Error
ack! yes. i missed this, conflating these with the JS and CSS things. you can't
type switch usefully on interface types. (see my recent blog post on
golang.org). these need to be concrete types. they can be just strings, as long
as they implement String()
thinking out loud and maybe stupidly, you could do
type errBase string
func (e ErrBase) String() string {
return string(e)
}
and then
type ErrBranchEnd struct { errBase }
that saves writing out the String method each time, but it's hardly a major
saving. they could just be strings too.
A broader question is why are these errors separate types? It's not like a user ...
12 years, 8 months ago
(2011-09-15 01:44:03 UTC)
#5
A broader question is why are these errors separate types? It's not like a user
of this package is going to do different things depending on whether the error
return is an ErrPartialCharset or an ErrPartialEscape. Either way, the template
is not HTML-escapable, and the reason why is already captured by err.String().
I think it's perfectly laudable to make the package's error messages consistent,
and well documented, but I don't think that that requires a separate Go type for
each type of error. Instead, have all of the error messages look like
"htmltemplate: partial charset: foobar" and have the string "partial charset" in
the error section of the package documentation.
This is just my immediate reaction, though. I might need to think a bit more
about it.
One possibility is type Error struct { ErrorCode ErrorCode Line int Detail string } func ...
12 years, 8 months ago
(2011-09-15 01:50:05 UTC)
#6
One possibility is
type Error struct {
ErrorCode ErrorCode
Line int
Detail string
}
func (e *Error) String() {
return fmt.Sprintf("htmltemplate: %v at line %d: %s", e.ErrorCode, e.Line,
e.Detail)
}
type ErrorCode int
const (
OK ErrorCode = iota
ErrAmbiguousContext
ErrBranchEnd
ErrEndContext
)
func (e ErrorCode) String() {
// look up a [...]
}
On 2011/09/15 01:50:05, nigeltao wrote: > One possibility is > > type Error struct { ...
12 years, 8 months ago
(2011-09-15 01:54:43 UTC)
#7
On 2011/09/15 01:50:05, nigeltao wrote:
> One possibility is
>
> type Error struct {
> ErrorCode ErrorCode
I like this. Latest snapshot does not have it but will implement.
http://codereview.appspot.com/5026041/diff/5001/src/pkg/exp/template/html/err...
File src/pkg/exp/template/html/error.go (right):
http://codereview.appspot.com/5026041/diff/5001/src/pkg/exp/template/html/err...
src/pkg/exp/template/html/error.go:52: ErrAmbigContext os.Error
On 2011/09/15 01:33:32, nigeltao wrote:
> I'm coming in late to this CL, and I don't know how it plays with godoc, but
I'd
> add a blank line afterwards to break up this enormous chunk of text. Similarly
> after each type below.
Done.
http://codereview.appspot.com/5026041/diff/5001/src/pkg/exp/template/html/err...
src/pkg/exp/template/html/error.go:62: // run-time value of {{.C}}.
On 2011/09/15 01:03:45, r wrote:
> didn't i have a much shorter version of this? this is too long.
You did, I misinterpreted
"[r: i think this is too much detail. i’ve distilled it up top but left this
here for reference"
and left the bracketed content in. Removed.
http://codereview.appspot.com/5026041/diff/5001/src/pkg/exp/template/html/err...
src/pkg/exp/template/html/error.go:105: ErrBranchEnd os.Error
On 2011/09/15 01:43:11, r wrote:
> ack! yes. i missed this, conflating these with the JS and CSS things. you
can't
> type switch usefully on interface types. (see my recent blog post on
> http://golang.org). these need to be concrete types. they can be just strings,
as long
> as they implement String()
>
> thinking out loud and maybe stupidly, you could do
>
> type errBase string
> func (e ErrBase) String() string {
> return string(e)
> }
>
> and then
>
> type ErrBranchEnd struct { errBase }
>
> that saves writing out the String method each time, but it's hardly a major
> saving. they could just be strings too.
I just made them a string.
http://codereview.appspot.com/5026041/diff/5001/src/pkg/exp/template/html/esc...
File src/pkg/exp/template/html/escape.go (right):
http://codereview.appspot.com/5026041/diff/5001/src/pkg/exp/template/html/esc...
src/pkg/exp/template/html/escape.go:480: args, f = append([]interface{}{e.name,
line}, args...), "%s:%d: "+f
On 2011/09/15 01:03:45, r wrote:
> you don't need this; it's easy:
> return fmt.Errorf("%s:%d: "+f, e.name, line, args...)
That doesn't seem to work.
escape.go:480: too many arguments in call to fmt.Errorf
On 2011/09/15 01:50:05, nigeltao wrote: > One possibility is > > type Error struct { ...
12 years, 8 months ago
(2011-09-15 02:17:47 UTC)
#8
On 2011/09/15 01:50:05, nigeltao wrote:
> One possibility is
>
> type Error struct {
> ErrorCode ErrorCode
> Line int
> Detail string
> }
>
> func (e *Error) String() {
> return fmt.Sprintf("htmltemplate: %v at line %d: %s", e.ErrorCode, e.Line,
> e.Detail)
> }
>
> type ErrorCode int
>
> const (
> OK ErrorCode = iota
> ErrAmbiguousContext
> ErrBranchEnd
> ErrEndContext
> )
>
> func (e ErrorCode) String() {
> // look up a [...]
> }
Done. ErrorCode is called ErrorKind because I saw that name in another package
I think.
http://codereview.appspot.com/5026041/diff/15003/src/pkg/exp/template/html/error.go File src/pkg/exp/template/html/error.go (right): http://codereview.appspot.com/5026041/diff/15003/src/pkg/exp/template/html/error.go#newcode20 src/pkg/exp/template/html/error.go:20: s string You might as well export all the ...
12 years, 8 months ago
(2011-09-15 08:28:42 UTC)
#10
LGTM leaving for nigeltao http://codereview.appspot.com/5026041/diff/11003/src/pkg/exp/template/html/doc.go File src/pkg/exp/template/html/doc.go (right): http://codereview.appspot.com/5026041/diff/11003/src/pkg/exp/template/html/doc.go#newcode73 src/pkg/exp/template/html/doc.go:73: explanation of the problem. See ...
12 years, 8 months ago
(2011-09-15 19:33:14 UTC)
#13
Incremental diffs at http://codereview.appspot.com/5026041/diff2/11003:28001/src/pkg/exp/template/html/doc.go http://codereview.appspot.com/5026041/diff/11003/src/pkg/exp/template/html/doc.go File src/pkg/exp/template/html/doc.go (right): http://codereview.appspot.com/5026041/diff/11003/src/pkg/exp/template/html/doc.go#newcode73 src/pkg/exp/template/html/doc.go:73: explanation of the problem. On ...
12 years, 8 months ago
(2011-09-15 20:13:49 UTC)
#14
LGTM. http://codereview.appspot.com/5026041/diff/28001/src/pkg/exp/template/html/error.go File src/pkg/exp/template/html/error.go (right): http://codereview.appspot.com/5026041/diff/28001/src/pkg/exp/template/html/error.go#newcode26 src/pkg/exp/template/html/error.go:26: // We define types for each error that ...
12 years, 8 months ago
(2011-09-16 00:46:18 UTC)
#15
Issue 5026041: code review 5026041: exp/template/html: moved error docs out of package docs...
(Closed)
Created 12 years, 8 months ago by MikeSamuel
Modified 12 years, 8 months ago
Reviewers:
Base URL:
Comments: 45