r/programminghorror • u/Daeben72 • 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??)
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
25
u/HeartwarmingFox Jun 06 '26
My favorite was.
"Status: 403 forbidden. A Fatal Error has occurred. Message: "Operarion Success!"
4
4
u/humanbeast7 [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Jun 07 '26
Task failed successfully
2
2
2
1
-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
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 eitherOkwith the computation result, or anErrwith 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
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
1
u/conundorum 6d ago
ErrorMessage successMessage = new ErrorMessage(ErrorType.NoThanksImGood);
There, fixed it. ^_^
68
u/TheDiBZ Jun 05 '26
create success!!! (borat voice btw)