[I would like to post this on the issue tracker, tho it's not a proposal or bug report. Is that OK?]
Re the Go 2 draft design for error handling, there are thirty-something counter-proposals on the
feedback wiki! I don't imagine that's the sort of feedback that the authors hoped for.
Apparently many folks see different requirement
sets for a new error-handling idiom, and the union of the sets is broad,
but the draft design targets a narrow set. Hence the dozens of
"better ideas" on the wiki, each conceived for different requirements. I think the Go team would benefit from a consensus on the
requirements before penning a next draft.
The draft design
Overview gives just four rather vague "goals": small-footprint error checks, developer-friendly error handlers,
explicit checks & handlers, and compatibility with existing code. And previously @ianlancetaylor made this similar list:
Below is a comprehensive list of possible requirements. Please respond with any others that should be considered.
a) A less verbose error handling idiom than if err != nil { recurring_stmt }
a.1) Allow Go1 error idiom to continue working
b) Concise, reusable error "handlers" within a function and/or package
c) Let a statement select one of several handlers by name
>1/3rd of wiki posts suggest this
c.1) Ways that handlers could be uniquely identified, one of:
handler name, parameter name, label, ...
c.2) Classes of syntax to select a named handler.
A left-side and a right-side style could both be valid
op is a keyword or symbol; space between symbol and identifier is optional
v, handler op := f(p)
v, op handler := f(p)
v := op(f(p), handler)
v := op(handler, f(p))
v := f(p) op handler
v := handler op f(p)
v := f op handler(p) // n.b.
d) Let function returning error nest in function calls, e.g.
x(f op handler (p)) // where func f(int)(int, error)
e) Let handler accept any return value, or only last one.
e.1) Let index of return value be specified (if not last one) when nested in function call, e.g.
x(f op handler . digit (p))
f) Let handler accept any type, or only type error
g) Let handler continue the function, e.g.
{ if err == io.EOF { break } } // stop enclosing loop, etc
h) Let handler invoke another handler explicitly, e.g.
{ if err != io.EOF { op quit = err } } // invoke "quit" handler
h.1) Let handler invoke another handler implicitly,
e.g. handlers with same name in related scopes.
i) Let handler perform context accretion, e.g.
{ return fmt.Errorf("blurb: %v", err) }
j) Placement of handler relative to statements that invoke it, either:
before, after
k) Permit package-level handler, accessible from any package function,
a variation on the "default handler" concept.
l) Provide a "default handler" to simply return input, named one of:
op _, op default, op return, ...
l.1) Behavior of default handler in main & goroutine functions which don't return, either:
panic, nothing
l.2) Provide a panicking default handler, e.g.
op panic = f(p) // or op ! etc
m) Consider new keywords, one of:
any new keywords
only established C/C++/Java keywords
no new keywords