aboutsummaryrefslogtreecommitdiff
path: root/src/errors/errors.go
diff options
context:
space:
mode:
authorMarcel van Lohuizen <mpvl@golang.org>2019-02-22 23:41:38 +0100
committerMarcel van Lohuizen <mpvl@golang.org>2019-02-27 19:07:22 +0000
commit37f84817247d3b8e687a701ccb0d6bc7ffe3cb78 (patch)
tree2d7434960e6f7b76acec199a8e7dfc032a5c2688 /src/errors/errors.go
parent1d992f2e369e7e518ff57cd7508a15442d5df186 (diff)
downloadgo-37f84817247d3b8e687a701ccb0d6bc7ffe3cb78.tar.xz
errors: add Frame and Formatter/Printer interfaces
errors.New now implements Formatter and includes Frame information that is reported when detail is requested. Partly implements proposal Issue #29934. Change-Id: Id76888d246d7d862595b5e92d517b9c03f23a7a6 Reviewed-on: https://go-review.googlesource.com/c/163557 Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/errors/errors.go')
-rw-r--r--src/errors/errors.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/errors/errors.go b/src/errors/errors.go
index b8a46921be..f23a96c43e 100644
--- a/src/errors/errors.go
+++ b/src/errors/errors.go
@@ -6,15 +6,25 @@
package errors
// New returns an error that formats as the given text.
+//
+// The returned error contains a Frame set to the caller's location and
+// implements Formatter to show this information when printed with details.
func New(text string) error {
- return &errorString{text}
+ return &errorString{text, Caller(1)}
}
// errorString is a trivial implementation of error.
type errorString struct {
- s string
+ s string
+ frame Frame
}
func (e *errorString) Error() string {
return e.s
}
+
+func (e *errorString) FormatError(p Printer) (next error) {
+ p.Print(e.s)
+ e.frame.Format(p)
+ return nil
+}