Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errors: examples need improvement #31716

Open
FiloSottile opened this issue Apr 27, 2019 · 4 comments
Open

errors: examples need improvement #31716

FiloSottile opened this issue Apr 27, 2019 · 4 comments

Comments

@FiloSottile
Copy link
Member

@FiloSottile FiloSottile commented Apr 27, 2019

There is a total of 4 examples in the package. Two are for New, one doesn't use the package at all, and one incorrectly uses As by dropping the error on the floor if it's not a os.PathError.

	_, err := os.Open("non-existing")
	if err != nil {
		var pathError *os.PathError
		if errors.As(err, &pathError) {
			fmt.Println("Failed at path:", pathError.Path)
		}
	}
@FiloSottile FiloSottile added this to the Go1.13 milestone Apr 27, 2019
@corona10
Copy link
Contributor

@corona10 corona10 commented Apr 30, 2019

@FiloSottile Can I take a look at this issue?

@gopherbot
Copy link

@gopherbot gopherbot commented May 4, 2019

Change https://golang.org/cl/175257 mentions this issue: errors: Add errors.Is examples

@gopherbot
Copy link

@gopherbot gopherbot commented May 31, 2019

Change https://golang.org/cl/179737 mentions this issue: errors: fix package example

gopherbot pushed a commit that referenced this issue Jun 3, 2019
The example in example_test.go requires that the whole file be
displayed; the addition of ExampleAs meant that only the body of the
package example function was shown, rather than the surrounding context.

This change moves ExampleAs to the file wrap_test.go file, restoring the
package example to its former glory.

Update #31716

Change-Id: Id0ea77bc06023b239a63c1d6a7c8b3c1dae91ce9
Reviewed-on: https://go-review.googlesource.com/c/go/+/179737
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Reviewed-by: Jean de Klerk <deklerk@google.com>
Run-TryBot: Benny Siegert <bsiegert@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@gopherbot
Copy link

@gopherbot gopherbot commented Apr 12, 2020

Change https://golang.org/cl/228038 mentions this issue: errors: add example for Is

gopherbot pushed a commit that referenced this issue Apr 13, 2020
Add ExampleIs to illustrate how errors.Is works.

Updates #31716.
Updates #38369.

Change-Id: I1b9a6667614635aa3a5ed8b2c108d8eb6f35748b
Reviewed-on: https://go-review.googlesource.com/c/go/+/228038
Reviewed-by: Damien Neil <dneil@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.