Skip to content

fmsg: add a shorthand for formatted With#44

Merged
Southclaws merged 2 commits intomasterfrom
unknown repository
Jun 14, 2025
Merged

fmsg: add a shorthand for formatted With#44
Southclaws merged 2 commits intomasterfrom
unknown repository

Conversation

@ghost
Copy link

@ghost ghost commented Jun 14, 2025

TL;DR

A simple shorthand that combines fmsg.With() + fmt.Sprintf() for improved DX.

Why

First of all, great library!

But after writing this pattern (not exaggerating here) a thousands of times, I'm pretty sick of it:

err := ThingThatCanReturnError(id)
if err != nil{
    return fault.Wrap(err, fmsg.With(fmt.Sprintf("call ThingThatCanReturnError with id::%s", id)))
}

It's pretty verbose. But most annoyingly I have a linter that complains if a line is more than 150 characters long. And funnily enough that additional fmt.Sprintf is what gets it over the 150 pretty often (nope, can't just disable that).

So I'd like to add a shorthand for that operation. Just like there's fault.New and fault.Newf, I feel like there should be a fmsg.Withf function

@Southclaws
Copy link
Owner

I've actually been meaning to add this for ages, thanks! The same thing has annoyed me and I didn't get around to it!

@Southclaws Southclaws merged commit 15e49ae into Southclaws:master Jun 14, 2025
2 checks passed
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

Successfully merging this pull request may close these issues.

1 participant

Comments