aboutsummaryrefslogtreecommitdiff
path: root/src/errors
AgeCommit message (Collapse)Author
2020-10-20all: update references to symbols moved from os to io/fsRuss Cox
The old os references are still valid, but update our code to reflect best practices and get used to the new locations. Code compiled with the bootstrap toolchain (cmd/asm, cmd/dist, cmd/compile, debug/elf) must remain Go 1.4-compatible and is excluded. For #41190. Change-Id: I8f9526977867c10a221e2f392f78d7dec073f1bd Reviewed-on: https://go-review.googlesource.com/c/go/+/243907 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2020-04-13errors: add example for IsJonathan Amsterdam
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>
2020-03-09errors: fix typo in As documentationYann Salaün
Change-Id: Ia26b4457aa0780171a636df93f8d210de0278ec5 GitHub-Last-Rev: 577a6fec336010cb56a547bf2d6304fd3e0cb257 GitHub-Pull-Request: golang/go#37760 Reviewed-on: https://go-review.googlesource.com/c/go/+/222621 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-10-11errors: fix typo in TODO commentdavidsbond
Fixes #34846 Change-Id: I24b3e65fc96ec85b2821480e9396c9d1663611c4 Reviewed-on: https://go-review.googlesource.com/c/go/+/200678 Run-TryBot: Johan Brandhorst <johan.brandhorst@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Johan Brandhorst <johan.brandhorst@gmail.com>
2019-09-06errors: clarify docs for when As returns falseIan Lance Taylor
Change-Id: Ic8d8399f726c1f9376499fdae92bea41632586ff Reviewed-on: https://go-review.googlesource.com/c/go/+/193602 Reviewed-by: Jonathan Amsterdam <jba@google.com>
2019-09-04errors: fix wrong code in package docJonathan Amsterdam
You can't call Unwrap on the return value of fmt.Errorf, but you can pass the result to errors.Unwrap. Also, move the description of the Unwrap function up so the example makes sense. Fixes #34061. Change-Id: Ica07c44665c5e65deea4aa6a146fc543a5a0a99d Reviewed-on: https://go-review.googlesource.com/c/go/+/193298 Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Katie Hockman <katie@golang.org>
2019-08-27errors: document Is and As methodsJonathan Amsterdam
Add brief descriptions of why one might implement an Is or As method. Fixes #33364. Change-Id: I81a091bf564c654ddb9ef3997e780451a01efb7a Reviewed-on: https://go-review.googlesource.com/c/go/+/191338 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Andrew Bonventre <andybons@golang.org> Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-26Revert "errors: add example showing a custom error with Unwrap"Andrew Bonventre
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>
2019-08-25errors: add example showing a custom error with UnwrapJonathan Amsterdam
Change-Id: I2bddee9b460d3875911859b49528a00d318f37fc Reviewed-on: https://go-review.googlesource.com/c/go/+/184237 Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-08-06errors: improve docJonathan Amsterdam
Explain wrapping and how to use Is and As in the package doc. Explain "chain" in Is and As. Updates #33364. Change-Id: Ic06362106dbd129e33dd47e63176ee5355492086 Reviewed-on: https://go-review.googlesource.com/c/go/+/188737 Reviewed-by: Rob Pike <r@golang.org>
2019-06-11errors: clarify doc for AsJonathan Amsterdam
Change-Id: I389d140e8fd2849e4dc438246add47819f6b25a3 Reviewed-on: https://go-review.googlesource.com/c/go/+/181300 Reviewed-by: Bryan C. Mills <bcmills@google.com>
2019-06-11errors: improve As testsJonathan Amsterdam
Check the value of target after As returns true. Change-Id: I76a2b25fe825ee1dbb5f39f8f0b211c55bd25a4f Reviewed-on: https://go-review.googlesource.com/c/go/+/181299 Reviewed-by: Bryan C. Mills <bcmills@google.com>
2019-06-03errors: fix package exampleAndrew Gerrand
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>
2019-05-22errors: remove mention of Wrapper interfaceDamien Neil
The Wrapper type no longer exists. Change-Id: I21051f26c6722a957295819f2f385f2bbd0db355 Reviewed-on: https://go-review.googlesource.com/c/go/+/177618 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-05-17errors: update As example to include else caseJean de Klerk
The current example illustrates using As when the error is able to be interpreted as an os.PathError, but elides the "else" case. This CL adds the small extra else case to make it clear that it's not safe to assume As will return true. This CL also squash the err instantiation and the err nil check into one line for brevity. Change-Id: I3d3ab483ffb38fb2788d0498b3f03229a87dd7c3 Reviewed-on: https://go-review.googlesource.com/c/go/+/177717 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-15errors, fmt: revert rejected changes for Go 1.13Damien Neil
Reverts the following changes: https://go.googlesource.com/go/+/1f90d081391d4f5911960fd28d81d7ea5e554a8f https://go.googlesource.com/go/+/8bf18b56a47a98b9dd2fa03beb358312237a8c76 https://go.googlesource.com/go/+/5402854c3557f87fa2741a52ffc15dfb1ef333cc https://go.googlesource.com/go/+/37f84817247d3b8e687a701ccb0d6bc7ffe3cb78 https://go.googlesource.com/go/+/6be6f114e0d483a233101a67c9644cd72bd3ae7a Partially reverts the followinng change, removing the errors.Opaque function and the errors.Wrapper type definition: https://go.googlesource.com/go/+/62f5e8156ef56fa61e6af56f4ccc633bde1a9120 Updates documentation referencing the Wrapper type. Change-Id: Ia622883e39cafb06809853e3fd90b21441124534 Reviewed-on: https://go-review.googlesource.com/c/go/+/176997 Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
2019-05-13errors: remove useless condition checking in IsLE Manh Cuong
golang.org/cl/175260 fixed Is panics if target is uncomparable. It did add an useless condition checking whether target is comparable. Just remove that condition. Change-Id: I0a317056479638d209b0a0cbc7010c153558c087 Reviewed-on: https://go-review.googlesource.com/c/go/+/176497 Reviewed-by: Joan Lopez de la Franca Beltran <joanjan14@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-05-06errors: fix Is panics if target is uncomparableLE Manh Cuong
Fixes #31841 Change-Id: I3f068686154fd2fa5755b0df47b4eaa5c9a19107 Reviewed-on: https://go-review.googlesource.com/c/go/+/175260 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-05-02errors: fix comment referencing the Wrapper interfaceJacob Walker
The Unwrap function performs a type assertion looking for the Wrapper interface. The method of that interface is called Unwrap but the interface itself is called Wrapper. Change-Id: Ie3bf296f93b773d36015bcab2a0e6585d39783c7 GitHub-Last-Rev: 32b1a0c2f8bf8f3eaebf6de252571d82313e86e0 GitHub-Pull-Request: golang/go#31794 Reviewed-on: https://go-review.googlesource.com/c/go/+/174917 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-04-10errors: return false if nil error is passed to AsAhsun Ahmed
Fixes #30970 Change-Id: I333676b55a2364e329fffeafca8fc57d45a0b84b Reviewed-on: https://go-review.googlesource.com/c/go/+/168598 Reviewed-by: Marcel van Lohuizen <mpvl@golang.org> Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-03-14fmt: make type of fmt.Errorf the same as that of errors.NewMarcel van Lohuizen
This applies only for cases where %w is not used. The purpose of this change is to reduce test failures where tests depend on these two being the same type, as they previously were. Change-Id: I2dd28b93fe1d59f3cfbb4eb0875d1fb8ee699746 Reviewed-on: https://go-review.googlesource.com/c/go/+/167402 Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
2019-03-14errors: improve performance of NewMarcel van Lohuizen
See Issue #29382 and Issue #30468. Improvements in this CL: name old time/op new time/op delta New-8 352ns ± 2% 225ns ± 5% -36.04% (p=0.008 n=5+5) Improvements together with moving to 1 uintptr: name old time/op new time/op delta New-8 475ns ± 3% 225ns ± 5% -52.59% (p=0.008 n=5+5) Change-Id: I9d69a14e5e10a6498767defb7d5f26ceedcf9ba5 Reviewed-on: https://go-review.googlesource.com/c/go/+/167401 Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
2019-03-14errors: record only single frameMarcel van Lohuizen
See Issue #29382 and Issue #30468. 3 frames are no longer needed as of https://go-review.googlesource.com/c/go/+/152537/ name old time/op new time/op delta New-8 475ns ± 3% 352ns ± 2% -25.87% (p=0.008 n=5+5) Errorf/no_format-8 661ns ± 4% 558ns ± 2% -15.63% (p=0.008 n=5+5) Errorf/with_format-8 729ns ± 6% 626ns ± 2% -14.23% (p=0.008 n=5+5) Errorf/method:_mytype-8 1.00µs ± 9% 0.84µs ± 2% -15.94% (p=0.008 n=5+5) Errorf/method:_number-8 1.25µs ± 7% 1.04µs ± 2% -16.38% (p=0.008 n=5+5) Change-Id: I30377e769b3b3be623f63ecbe365f8950ca08dda Reviewed-on: https://go-review.googlesource.com/c/go/+/167400 Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
2019-02-27errors: add Unwrap, Is, and AsMarcel van Lohuizen
Unwrap, Is and As are as defined in proposal Issue #29934. Also add Opaque for enforcing an error cannot be unwrapped. Change-Id: I4f3feaa42e3ee7477b588164ac622ba4d5e77cad Reviewed-on: https://go-review.googlesource.com/c/163558 Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
2019-02-27errors: add Frame and Formatter/Printer interfacesMarcel van Lohuizen
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>
2016-03-01all: make copyright headers consistent with one space after periodBrad Fitzpatrick
This is a subset of https://golang.org/cl/20022 with only the copyright header lines, so the next CL will be smaller and more reviewable. Go policy has been single space after periods in comments for some time. The copyright header template at: https://golang.org/doc/contribute.html#copyright also uses a single space. Make them all consistent. Change-Id: Icc26c6b8495c3820da6b171ca96a74701b4a01b0 Reviewed-on: https://go-review.googlesource.com/20111 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2014-09-08build: move package sources from src/pkg to srcRuss Cox
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.