I've had some ongoing confusion about using errors.As (see https://play.golang.com/p/m4_cXCzOViD). The issue I'm having is this part of the contract:> An error matches target if the error's concrete value is assignable to the value pointed to by targetI always expected (yes, I know), that base and pointer receivers are interchangeable. This is not the case (see playground). This seems to make using it error-prone as you'll always need to carefully think about the return type of the function invoked. While the contract is always error, a function may return a base or a pointer error type. This influences how using errors.As must be done.Are there best practices for:- return base vs. pointer errors
- crafting the errors.As target type without inspecting the actual function invoked...and could it make sense to lessen errors.As to match pointer with non-pointer receivers?Thanks!
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/afe2df8a-9e42-4511-abe6-8e03b906d637n%40googlegroups.com.
I myself still use the classic string based-errors asoriginal designed.
I don't think there is a wide accepted best practice here.
There arelibraries like "errors" but to me wrapping errors is gratuitous complexity thatonly adds noise. That's not a general consensus; just one practitioner's opinion.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/b0d1a19c-8025-4c36-ad39-a3c0571de3c9n%40googlegroups.com.
On Fri, 14 Feb 2025 at 14:24, Axel Wagner wrote:
On Fri, 14 Feb 2025 at 14:05, Jason E. Aten wrote:I myself still use the classic string based-errors asoriginal designed.I'm not sure what you mean here.
On Fri, 14 Feb 2025 at 14:24, Axel Wagner <axel.wa...@googlemail.com> wrote:On Fri, 14 Feb 2025 at 14:05, Jason E. Aten <j.e....@gmail.com> wrote:I myself still use the classic string based-errors asoriginal designed.I'm not sure what you mean here.