aboutsummaryrefslogtreecommitdiff
path: root/src/errors
diff options
context:
space:
mode:
authorAndrew Bonventre <andybons@golang.org>2019-08-26 01:25:41 +0000
committerJonathan Amsterdam <jba@google.com>2019-08-26 02:18:15 +0000
commit78f6856ddf855a457bd33af27089cb3f6e1b2a2d (patch)
tree67508afc746a2f9f7778f7849726518de9c67d5f /src/errors
parent89fb80f7fae1359a57968fbe600fc69b7296dd2d (diff)
downloadgo-78f6856ddf855a457bd33af27089cb3f6e1b2a2d.tar.gz
go-78f6856ddf855a457bd33af27089cb3f6e1b2a2d.zip
Revert "errors: add example showing a custom error with Unwrap"
This reverts commit 739123c3a36f30af06c294741f74a26e54ee21ad. Reason for revert: broke Windows and Plan 9 builders Fixes #33828 Change-Id: I1d85c81549b1b34924fdd0ade8bf9406e5cf6555 Reviewed-on: https://go-review.googlesource.com/c/go/+/191742 Run-TryBot: Andrew Bonventre <andybons@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jonathan Amsterdam <jba@google.com>
Diffstat (limited to 'src/errors')
-rw-r--r--src/errors/example_unwrap_test.go56
1 files changed, 0 insertions, 56 deletions
diff --git a/src/errors/example_unwrap_test.go b/src/errors/example_unwrap_test.go
deleted file mode 100644
index 05c9cd466f..0000000000
--- a/src/errors/example_unwrap_test.go
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2019 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package errors_test
-
-import (
- "errors"
- "fmt"
- "os"
- "time"
-)
-
-// MyError2 is an error implementation that includes a time, a message, and an
-// underlying error.
-type MyError2 struct {
- When time.Time
- What string
- err error
-}
-
-func (e MyError2) Error() string {
- return fmt.Sprintf("%v at %v: %v", e.What, e.When, e.err)
-}
-
-// Unwrap returns e's underlying error, or nil if there is none.
-func (e MyError2) Unwrap() error {
- return e.err
-}
-
-func readConfig() error {
- if _, err := os.Open("non-existing"); err != nil {
- return MyError2{
- time.Date(1989, 3, 15, 22, 30, 0, 0, time.UTC),
- "reading config file",
- err,
- }
- }
- return nil
-}
-
-func Example_unwrap() {
- if err := readConfig(); err != nil {
- // Display the error.
- fmt.Println(err)
- // If we can retrieve the path, try to recover
- // by taking another action.
- var pe *os.PathError
- if errors.As(err, &pe) {
- restoreFile(pe.Path)
- }
- }
- // Output: reading config file at 1989-03-15 22:30:00 +0000 UTC: open non-existing: no such file or directory
-}
-
-func restoreFile(path string) {}