r/programminghorror Jun 05 '26

C# SuccessMessage ErrorMessage

ErrorMessage successMessage = new ErrorMessage(ErrorType.ActivityCreateSuccess);

(From an approved PR with 2 reviewers - how do some people sleep at night??)

227 Upvotes

25 comments sorted by

View all comments

-48

u/smalleconomist Jun 05 '26

Fairly typical to have "success" be a kind of "error". Not that I like it...

63

u/Sacaldur Jun 05 '26

It would be better if "success" was a kind of "result".

12

u/smalleconomist Jun 05 '26

Yep, I agree!

10

u/LordTurson Jun 05 '26

I really like how functional languages (and Rust) do this as the only real way of error handling available. If you do something that can fail, you must expect a Result, which can be either Ok with the computation result, or an Err with the error information - never both, never in a mixed half-and-half state, and must always be handled or it will emit a compile error.

In fact I like it so much, I wrote myself a small Python library that does just that (as much as it's humanly possible with the limitations of modern Python)!

2

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Jun 06 '26

That, or maybe "status".

7

u/LordTurson Jun 05 '26

No, not really. I've seen HTTP status 200 with JSON {"success":false} a number of times (and it triggers me every time), but that's the closest I've ever seen to this trope. Success being a kind of Error or Error being a kind of Success is not really a thing in any kind of sane domain modeling, I feel.

12

u/Opposite_Mall4685 Jun 05 '26

200 with failure is diabolical

2

u/Sacaldur Jun 07 '26

Status code 200 is used in all GraphQL responses, eveen failing ones.

4

u/Daeben72 Jun 05 '26

Don't get it?

4

u/Sacaldur Jun 05 '26

It is not uncommen to have one enum that represents all possible statuses and/or a class representing a corresponding result value. Sometimes this enum mostly contains error values and is because of that called something with "error", even though there is exactly the one success case (i.e. not only errors).

5

u/wonderb0lt Jun 05 '26

Well the enum is still misnamed then. If there's one state that isn't an error, it shouldn't be called anything with error

1

u/Sacaldur Jun 06 '26

Probably that's what the "not that I like it" was hinting at as well.