Hello, I'm Maneshwar. I'm building git-lrc, a Micro AI code reviewer that runs on every commit. It is free and source-available on Github. Star Us to help devs discover the project. Do give it a try and share your feedback for improving the product.
So you wrote your first Go program. It compiled. You felt powerful. Then you saw this:
And you thought: "Wait... am I supposed to write if err != nil for the rest of my life?"
Yes, you are. But hear me out, it's actually kind of beautiful once you stop fighting it.
Why Go Did This To You (And Why It's Actually Fine)
Other languages treat errors like that one friend who shows up uninvited to your birthday party. They appear out of nowhere, ruin everything, and somebody else has to deal with them.
Go decided: errors are values. They're just things. Like strings. Or integers.
This means:
✅ Errors are visible in the function signature
✅ You can't accidentally ignore them (well, you can, but the linter will judge you)
✅ No invisible control flow jumping across 14 stack frames
❌ You have to type if err != nil approximately 9,000 times
It's a tradeoff. You'll grow to appreciate it. Or you'll switch to Rust. Both are valid.
When to use it: When you have nothing useful to add and the caller already has enough context.
When NOT to use it: When the caller is going to see unexpected end of JSON input and have absolutely no idea which of the 47 JSON files in your app caused it.
Pattern 2: Wrap It Like It's 1999
fmt.Errorf with %w. This is your new best friend. Treat them well.
Sometimes a string isn't enough. You want to attach data. You want a struct. You want to flex.
typeValidationErrorstruct{FieldstringMessagestring}func(e*ValidationError)Error()string{returnfmt.Sprintf("validation failed on %s: %s",e.Field,e.Message)}funcvalidateEmail(emailstring)error{if!strings.Contains(email,"@"){return&ValidationError{Field:"email",Message:"missing @ symbol, are you okay?",}}returnnil}
And the caller pulls out the type:
err:=validateEmail(input)varvErr*ValidationErroriferrors.As(err,&vErr){fmt.Printf("Hey, your %s is broken: %s\n",vErr.Field,vErr.Message)}
errors.As is errors.Is's overachieving cousin. It doesn't just check, it extracts.
Pattern 5: panic and recover (The Forbidden Techniques)
You may have heard of panic. Maybe you saw it in a library and felt a chill.
Rule of thumb: If you're panicking, you should probably be returning an error instead.
Real exceptions to the rule:
Truly unrecoverable situations (corrupt program state)
init() functions where the program literally can't start
Inside your own package, where you recover() at the boundary and convert to an error
funcMustCompile(patternstring)*Regexp{re,err:=Compile(pattern)iferr!=nil{panic(err)// genuinely fatal at startup}returnre}
If you're using panic for normal control flow, the Go gophers will find you. They have ways.
TL;DR For The Scrollers
Situation
Use This
Just bubbling it up with no extra info
return err
Want to add context
fmt.Errorf("doing X: %w", err)
Caller needs to check a specific error
Sentinel error + errors.Is
Caller needs error data
Custom type + errors.As
The world is ending
panic (sparingly!)
Final Thoughts
Yes, you'll write if err != nil a lot.
But here's the thing, once you stop seeing it as boilerplate and start seeing it as a decision point, every one of those blocks becomes a tiny little moment where you, the developer, get to think: "What does failure mean here? What does the caller need to know?"
That's not a burden. That's craftsmanship.
Now go forth and wrap your errors.
If you enjoyed this, drop a 🦫 in the comments. If you didn't, write if err != nil { return err } 100 times as penance.
*AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.
git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.*
Any feedback or contributors are welcome! It's online, source-available, and ready for anyone to use.
AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.
git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.
See It In Action
See git-lrc catch serious security issues such as leaked credentials, expensive cloud
operations, and sensitive material in log statements
git-lrc-intro-60s.mp4
Why
🤖 AI agents silently break things. Code removed. Logic changed. Edge cases gone. You won't notice until production.
🔍 Catch it before it ships. AI-powered inline comments show you exactly what changed and what looks wrong.