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

Wrapf Format Question #2

Open
karlkfi opened this issue Apr 12, 2015 · 3 comments
Open

Wrapf Format Question #2

karlkfi opened this issue Apr 12, 2015 · 3 comments

Comments

@karlkfi
Copy link

karlkfi commented Apr 12, 2015

For context, we have similar wrapping code here: https://github.com/cloudfoundry/bosh-agent/blob/master/errors/errors.go#L52

I'm wondering why you guys decided to allow the user to specify where (and if) the error string from the wrapped error gets included in the new error message.

Do you have special use cases where you need to format them differently? It seems like having a standard pattern would be sufficient, like fmt.Sprintf("%s: %s", msg, err.Error()).

We found that if more complex formatting was required the user could easily traverse the error chain and craft their own custom message format, like we did here: https://github.com/cloudfoundry/bosh-init/blob/master/ui/fmt/error.go

@glasser
Copy link

glasser commented Nov 25, 2015

I definitely find it a little surprising to discover that a Go function that ends in f doesn't take a standard format string.

@mitchellh
Copy link
Contributor

Ah, good question. I actually can't remember off the top of my head. We can easily make a BC change to allow normal format strings plus the {{err}} which we do already (for backwards compat). Let me think why, I definitely would've wanted a normal format string too I just can't remember the reason.

@AntonAM
Copy link

AntonAM commented Nov 1, 2018

Any update on this? Wrapf() is kinda misleading because it doesn't let you use regular format. And it's ugly when you have to use fmt.Sprintf() inside.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants