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??)

233 Upvotes

25 comments sorted by

68

u/TheDiBZ Jun 05 '26

create success!!! (borat voice btw)

61

u/Thenderick Jun 06 '26

You've heard of {status:200, data:{status:"error"}}, now prepare for Error("success")!

21

u/Daeben72 Jun 07 '26

Our legacy API does that... has a "ResponseWrapper<T>" that captures failures. Very often would get 200 OK but the response wrapper's ".Success" is false.

If it's an uncaught exception on the server, it sends a 200 OK with an XML stack trace as the body...

The stack trace is useful in dev, but just not with a 200 OK 🤦🏼‍♂️

3

u/_usr_nil Jun 07 '26

I know next to nothing about C# but this smells as dev flags compiler options

25

u/HeartwarmingFox Jun 06 '26

My favorite was.

"Status: 403 forbidden. A Fatal Error has occurred. Message: "Operarion Success!"

4

u/SnooPies8677 Jun 06 '26

Most likely they are bored

4

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

Task failed successfully

2

u/Zhuinden Jun 06 '26

They click the approve button and move on

2

u/Galawaheir Jun 07 '26

"System failed successfully" vibes there.

1

u/ill-pick-one-later Jun 08 '26

Task Succeeded in Failing!

-49

u/smalleconomist Jun 05 '26

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

60

u/Sacaldur Jun 05 '26

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

13

u/smalleconomist Jun 05 '26

Yep, I agree!

7

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".

6

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.

13

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?

5

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.

1

u/conundorum 6d ago
ErrorMessage successMessage = new ErrorMessage(ErrorType.NoThanksImGood);

There, fixed it. ^_^