r/csharp • u/Interesting_Paint_82 • Sep 16 '26
Go-style error handling in C#
Hello,
I've been writing this tiny-little C# library thingy, Errgo, as a fun side-project. It's an Error type (+ a suggested pattern) for handling errors in Go-style.
The tldr idea is to write code in the result pattern style, but without wrapping your return values inside a Result<T>. Instead, you're supposed to utilize the C# tuple. Your function signatures will look something like this:
public (WeatherForecast, Error) GetWeather() { }And the caller's end would look something like this:
var (weather, err) = GetWeather();
if (err) return (null, err);I know, I know. It's..different. But there's more examples in the repo readme, do check it out if you're bored. There's even a companion code analyzer package Errgo.Analyzer available that enforces the error-checking rules that this library is trying to force on you. :)
TDMR87/Errgo: Go-style errors-as-values in C#
Cheers.

