summaryrefslogtreecommitdiff
path: root/src/errors
Commit message (Collapse)AuthorAgeFilesLines
* errors: improve the godoc for Join and UnwrapDaniel Nephin2023-03-302-1/+4
| | | | | | | | | | | | | | | | | | Document that errors returned by Join always implement Unwrap []error. Explicitly state that Unwrap does not unwrap errors with an Unwrap() []error method. Change-Id: Id610345dcf43ca54a9dde157e56c5815c5112073 GitHub-Last-Rev: 7a0ec450bd0b2b38eecb5b94eaec485f4a6debbd GitHub-Pull-Request: golang/go#59301 Reviewed-on: https://go-review.googlesource.com/c/go/+/480021 Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> Auto-Submit: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
* errors: clarify Join documentationDavid Bendory2023-03-171-1/+1
| | | | | | | | | | | | | | | | The previous documentation used a double-negative in describing Join behavior; this use of language could be confusing. This update removes the double-negative. Change-Id: If13e88682e865314a556e7d381143a97fa5486d9 GitHub-Last-Rev: 92b3f88a5d49229e71adafcfa7b1d01dcb7646f3 GitHub-Pull-Request: golang/go#59082 Reviewed-on: https://go-review.googlesource.com/c/go/+/477095 Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
* errors: add ErrUnsupportedAndy Pan2023-03-111-0/+15
| | | | | | | | | | | | | Fixes #41198 Change-Id: Ib33a11d0eb311f8e2b81de24d11df49e00b2fc81 Reviewed-on: https://go-review.googlesource.com/c/go/+/473935 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Andy Pan <panjf2000@gmail.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* errors: move example functions into example_test filefangguizhen2023-01-203-75/+77
| | | | | | | | | | | | | Change-Id: Ide70476698d82a51881802dd6bf05dd7abcd60e8 GitHub-Last-Rev: ddb251ded669d3dbbb96a05f4df7151c8d7c16d2 GitHub-Pull-Request: golang/go#57931 Reviewed-on: https://go-review.googlesource.com/c/go/+/462292 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com>
* errors: add test for Joinfangguizhen2022-10-171-0/+23
| | | | | | | | | | | | | Change-Id: I77c61211a488c66f1d445c0bf01e35aaf4f83565 GitHub-Last-Rev: c411a56a3b5215e6dd093be7069affb176b48dfd GitHub-Pull-Request: golang/go#56279 Reviewed-on: https://go-review.googlesource.com/c/go/+/443316 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
* errors, fmt: add support for wrapping multiple errorsDamien Neil2022-09-296-28/+230
| | | | | | | | | | | | | | | | | | | | | | | An error which implements an "Unwrap() []error" method wraps all the non-nil errors in the returned []error. We replace the concept of the "error chain" inspected by errors.Is and errors.As with the "error tree". Is and As perform a pre-order, depth-first traversal of an error's tree. As returns the first matching result, if any. The new errors.Join function returns an error wrapping a list of errors. The fmt.Errorf function now supports multiple instances of the %w verb. For #53435. Change-Id: Ib7402e70b68e28af8f201d2b66bd8e87ccfb5283 Reviewed-on: https://go-review.googlesource.com/c/go/+/432898 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Rob Pike <r@golang.org> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
* all: gofmt -w -r 'interface{} -> any' srcRuss Cox2021-12-132-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
* errors: add errors.Unwrap examplejiahua wang2021-11-051-0/+10
| | | | | | | | | | Change-Id: Id2336a6059f7a8d627e6c0661a4d4c05485b65f3 Reviewed-on: https://go-review.googlesource.com/c/go/+/355589 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Cherry Mui <cherryyz@google.com> Trust: Robert Findley <rfindley@google.com>
* errors: improve wording in As doc commentJosh Bleecher Snyder2021-11-021-1/+1
| | | | | | | | | "so" didn't have an antecedent. Change-Id: I27f7b334decea7bc34bfa3f3f2d3a79874c6fe90 Reviewed-on: https://go-review.googlesource.com/c/go/+/360797 Trust: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
* errors: mention Is methods should not call UnwrapMatt T. Proud2021-10-191-1/+2
| | | | | | | | | | | | | | | | | errors.Is internally unwraps the error until the error matches the target. Because of this, a user-authored Is method on an error type need not call errors.Unwrap on itself or the target, because that would make the unwrapping operation O(N^2). It is a subtle detail to remind authors for resource efficiency reasons. Change-Id: Ic1ba59a5bdbfe2c7cb51a2cba2537ab6de4a13ff Reviewed-on: https://go-review.googlesource.com/c/go/+/356789 Reviewed-by: Jean de Klerk <deklerk@google.com> Reviewed-by: Damien Neil <dneil@google.com> Trust: Jean de Klerk <deklerk@google.com> Trust: Damien Neil <dneil@google.com> Run-TryBot: Jean de Klerk <deklerk@google.com> TryBot-Result: Go Bot <gobot@golang.org>
* errors/wrap: do not call Elem() twiceVitaly Zdanevich2021-03-131-2/+2
| | | | | | | | | | | Change-Id: I2fe6037c45a0dfe25f946a92ff97b5e3fbd69bc0 GitHub-Last-Rev: 644d479a27c0eccfc0b37e1a560ca09e47b5a972 GitHub-Pull-Request: golang/go#44851 Reviewed-on: https://go-review.googlesource.com/c/go/+/299629 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Tobias Klauser <tobias.klauser@gmail.com>
* all: update references to symbols moved from os to io/fsRuss Cox2020-10-203-13/+14
| | | | | | | | | | | | | | | | | | 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>
* errors: add example for IsJonathan Amsterdam2020-04-131-0/+13
| | | | | | | | | | | 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>
* errors: fix typo in As documentationYann Salaün2020-03-091-1/+1
| | | | | | | | 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>
* errors: fix typo in TODO commentdavidsbond2019-10-111-1/+1
| | | | | | | | | 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>
* errors: clarify docs for when As returns falseIan Lance Taylor2019-09-061-2/+2
| | | | | | Change-Id: Ic8d8399f726c1f9376499fdae92bea41632586ff Reviewed-on: https://go-review.googlesource.com/c/go/+/193602 Reviewed-by: Jonathan Amsterdam <jba@google.com>
* errors: fix wrong code in package docJonathan Amsterdam2019-09-041-4/+4
| | | | | | | | | | | | | | | 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>
* errors: document Is and As methodsJonathan Amsterdam2019-08-271-1/+12
| | | | | | | | | | | | | | 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>
* Revert "errors: add example showing a custom error with Unwrap"Andrew Bonventre2019-08-261-56/+0
| | | | | | | | | | | | | | 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>
* errors: add example showing a custom error with UnwrapJonathan Amsterdam2019-08-251-0/+56
| | | | | | | 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>
* errors: improve docJonathan Amsterdam2019-08-062-0/+55
| | | | | | | | | | | | 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>
* errors: clarify doc for AsJonathan Amsterdam2019-06-111-8/+9
| | | | | | Change-Id: I389d140e8fd2849e4dc438246add47819f6b25a3 Reviewed-on: https://go-review.googlesource.com/c/go/+/181300 Reviewed-by: Bryan C. Mills <bcmills@google.com>
* errors: improve As testsJonathan Amsterdam2019-06-111-8/+27
| | | | | | | | 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>
* errors: fix package exampleAndrew Gerrand2019-06-032-16/+14
| | | | | | | | | | | | | | | | | | 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>
* errors: remove mention of Wrapper interfaceDamien Neil2019-05-221-2/+3
| | | | | | | | 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>
* errors: update As example to include else caseJean de Klerk2019-05-171-2/+3
| | | | | | | | | | | | | | | | | 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>
* errors, fmt: revert rejected changes for Go 1.13Damien Neil2019-05-156-266/+5
| | | | | | | | | | | | | | | | | | | | | | | 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>
* errors: remove useless condition checking in IsLE Manh Cuong2019-05-131-1/+1
| | | | | | | | | | | 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>
* errors: fix Is panics if target is uncomparableLE Manh Cuong2019-05-062-1/+22
| | | | | | | | | | | 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>
* errors: fix comment referencing the Wrapper interfaceJacob Walker2019-05-021-1/+1
| | | | | | | | | | | | 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>
* errors: return false if nil error is passed to AsAhsun Ahmed2019-04-102-5/+8
| | | | | | | | | | 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>
* fmt: make type of fmt.Errorf the same as that of errors.NewMarcel van Lohuizen2019-03-141-3/+18
| | | | | | | | | | | | | 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>
* errors: improve performance of NewMarcel van Lohuizen2019-03-141-1/+6
| | | | | | | | | | | | | | | | | | | | 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>
* errors: record only single frameMarcel van Lohuizen2019-03-142-16/+30
| | | | | | | | | | | | | | | | | | | | 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>
* errors: add Unwrap, Is, and AsMarcel van Lohuizen2019-02-273-0/+379
| | | | | | | | | | | | | 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>
* errors: add Frame and Formatter/Printer interfacesMarcel van Lohuizen2019-02-274-2/+145
| | | | | | | | | | | | | 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>
* all: make copyright headers consistent with one space after periodBrad Fitzpatrick2016-03-013-3/+3
| | | | | | | | | | | | | | | | | | | | | | 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>
* build: move package sources from src/pkg to srcRuss Cox2014-09-083-0/+107
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.