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

x/xerrors: update with new %w semantics #33143

Closed
zombiezen opened this issue Jul 17, 2019 · 10 comments
Closed

x/xerrors: update with new %w semantics #33143

zombiezen opened this issue Jul 17, 2019 · 10 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@zombiezen
Copy link
Contributor

The launch decision on #29934 mentions changing fmt.Errorf to permit %w anywhere in the format string. golang.org/cl/176998 updated fmt at tip to support this, but xerrors.Errorf has not been given the new semantics yet. Since xerrors will presumably be used as a transition package for folks writing libraries that need to support older versions of Go, I think it's still worth updating xerrors to include this behavior.

@jba @neild

What did you do?

https://play.golang.org/p/rL3z0G4cmnR

What did you expect to see?

err2: foo bar
err3: bar: foo

What did you see instead?

err2: %!w(*xerrors.errorString) bar
err3: bar: foo
@gopherbot gopherbot added this to the Unreleased milestone Jul 17, 2019
@earthboundkid
Copy link
Contributor

I ran into this myself. I tried to wrap with xerrors.Errorf("%w", err) and I was surprised when it didn't work. I debugged the wrong thing before changing it to ": %w".

@FiloSottile FiloSottile added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 17, 2019
@jba jba self-assigned this Jul 19, 2019
@jba
Copy link
Contributor

jba commented Jul 19, 2019

I have a (clumsy, incomplete) fix for this at https://go-review.googlesource.com/c/xerrors/+/186957.

@sidh
Copy link

sidh commented Nov 15, 2019

Would really like to see a fix for this too.

Current behavior is wrong - https://play.golang.org/p/QncO3iOhWji

@sidh
Copy link

sidh commented Dec 2, 2019

Any news on this issue?

@jba
Copy link
Contributor

jba commented Dec 4, 2019

I updated my CL to fix the problem @sidh pointed out. I'm waiting for a review.

@sidh
Copy link

sidh commented Dec 10, 2019

Another issue which actually has a TODO in the code - https://play.golang.org/p/KJZ0Uirj48r

@jba
Copy link
Contributor

jba commented Dec 10, 2019

(First, that CL was submitted, but for some reason this bug wasn't closed. I guess that's a blessing in disguise :)

@sidh, there are several such problems that would require better parsing of the format string. However, since Go 1.14 is coming out shortly and it will make xerrors obsolete, I don't think it's worth fixing them.

@jba
Copy link
Contributor

jba commented Dec 10, 2019

To clarify: once 1.14 is out, the only two officially supported versions of Go are 1.13 and 1.14, both of which have the new errors support. So if you follow the official policy, you can remove xerrors from your code.

@sidh
Copy link

sidh commented Dec 11, 2019

Yeah, I've updated our version already.

Problem with switching to stdlib version of errors is you will miss out on stack frames and neat formatting. May be there is another package out there, all compatible with 1.13 errors? I'd prefer not to write it myself if there is one.

@ALTree
Copy link
Member

ALTree commented Jul 20, 2020

Fixed in CL 186957.

@ALTree ALTree closed this as completed Jul 20, 2020
@golang golang locked and limited conversation to collaborators Jul 20, 2021
@rsc rsc unassigned jba Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

7 participants