Page 1 of 2

dedi-api: Exception Classes

Posted: 14 Apr 2014, 18:56
by steeffeen
Hey there,

I would like you to take a look at this draft for exception classes based on the fault messages.
https://github.com/ManiaControl/dedicat ... 778e3b6586

If each error message has its own class then you can explicitly catch them and don't need to compare the strings on all the possible occurrences.
Maybe it can be integrated in the official version? For that I would complete it if required.

Feedback welcome!

Thanks in advance,
Steff

Re: dedi-api: Exception Classes

Posted: 18 Apr 2014, 01:04
by The_Big_Boo
It seems like an interesting idea but I have some doubts.

- I'm not sure if doing the complete list is really useful.
I mean, it is useful if the number of different fault messages the dedicated can send is like a dozen but if it's more like a hundred, then only the most common ones should have their own class thus a hard question: how to choose them?

- Do these faults happen often enough?
From my experience, they're quite rare (partly because the Connection class is already checking arguments to avoid most of them) and come most of the time from programming mistakes, thus they disappear after debugging. For instance, the unkown (typo is a private joke) login fault should never happen.


I'm not against (it's not a big deal to add them), but do you have some real use cases so I can clearly see why it's a must-have? ^^

Re: dedi-api: Exception Classes

Posted: 18 Apr 2014, 15:30
by steeffeen
well that's not the best example ^^
i would rather like to describe the following situation:
- you display a player list with buttons for actions regarding each player
- one of these players leaves the server, now you get the "unknown login" error if an action for him is triggered
- to prevent this you would have to check again if the player is still on the server
- the player could have been removed from the playerlist between the check and the action (very unlikely but still possible i would think), again error
- so the check beforehands makes sense but can't prevent the exception completely

so it's not only caused by programming issues imo

Re: dedi-api: Exception Classes

Posted: 18 Apr 2014, 15:41
by steeffeen
to add:
you're right that not every error message needs an own class
though it would be great if one could distinguish between player related, script related or connection errors etc.
like you said it's hard to determine which errors deserve an own exception

a good alternative would be adding actual error codes
maybe similar to http error codes:

Code: Select all

1xx connection
2xx configuration
3xx script
4xx map
5xx player
etc.

though it might be complex to classify the errors
one could think a "Too many players." error would relate to players while i would put it into configuration (~server setting)

Re: dedi-api: Exception Classes

Posted: 18 Apr 2014, 18:08
by The_Big_Boo
Indeed, the team mode example isn't convincing :D However:
steeffeen wrote:- to prevent this you would have to check again if the player is still on the server
If the player has left, you should have been warned already by the server so if you track who's connected, it takes a nanosecond to check. The player can still left between the time you click on the action and the time the dedicated receives the command from your controller but this timespan is so short, it's indeed very unlikely to happen. Has anyone ever encountered this case? You still made a point though ^^


About your http-like error codes: it could only be done in the dedicated itself, else it means knowing the complete list of fault messages (good luck with that). And I think it's best anyway to keep the fault codes sent by the dedicated instead of overriding them with custom ones.

Re: dedi-api: Exception Classes

Posted: 18 Apr 2014, 18:11
by steeffeen
yeah my suggestion was regarding the dedicated itself
currently pretty much all errors have the code -1000 which isn't helpful at all ^^
i didn't mean to set the error codes in php, sorry if it was misleading

Re: dedi-api: Exception Classes

Posted: 18 Apr 2014, 19:05
by The_Big_Boo
Oh, alright then ^^

Anyway, I more or less merged your fork of dedicated-api in mine (https://github.com/NewboO/dedicated-server-api) which, I hope, will replace the current one. So you can make pull requests here if you like ;)