Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot crashes with a TS3CommandFailedException exception #402

Open
TOminerTV opened this issue Nov 19, 2021 · 3 comments
Open

Bot crashes with a TS3CommandFailedException exception #402

TOminerTV opened this issue Nov 19, 2021 · 3 comments

Comments

@TOminerTV
Copy link

Hello GitHub,

first of all, very nice api.
Unfortunately it is really buggy, regularly my bot crashes with a TS3CommandFailedException exception.
Examples are: on client kick, on client move, on client group set, etc.
The code that throws this exception is in a try-catch and this try-catch is in another global try-catch, unfortunately this doesn't work, the bot is still available on the Ts3 server but doesn't respond to anything anymore.

What can I do to avoid this problem, I check every time if the user is online but this does not work.
Is it possible to get null or boolean values from these methods instead of a bot crashing exception?

With kind regards
Tobias

@astrolamb-gaming
Copy link

Very little of your information there is particularly helpful. How exactly are you checking if a user is online? Without seeing your code I'm not sure anyone will be able to help you. I recommend the gitter to discuss more, since I stronly suspect you are using the api improperly.

@TOminerTV
Copy link
Author

TOminerTV commented Nov 19, 2021

As I said, the exception actually occurs with every method that the API offers to interact with clients. What else should I write about this? There is not even an explanation why this error is thrown, at least I could not find out anything so far, the links in the readme are partly not accessible anymore.

As I said, an example would be this call here:
ts3Api.addClientToServerGroup(configManager.getValue("greenWingGroup", Integer.class), client.getDatabaseId());

Here I am trying to assign a client to a group. The whole thing works, but at the same time I get the above-mentioned exception.

Here is still the whole class, the run method is called every 5 seconds by a scheduler. The whole thing is then in a try-catch.
https://pastebin.com/WvS56FhA

The main class with the try catch
https://pastebin.com/Y2BtniqP

EDIT: the configManager returns the an integer and has no errors

@rogermb
Copy link
Collaborator

rogermb commented Nov 20, 2021

Hi @TOminerTV

Exceptions don't propagate out of Timer.scheduleAtFixedRate. I mean, how could they? Your TimerTask runs on a different thread. You need to handle exceptions within your TimerTask's run method.

Moreover, consider how things can go wrong, and how you can recover from things going wrong. For example, between the time you ask the server for a list of clients and the time you want to add the client to a group, the client may have disconnected from the server. Or the TS3 server may have crashed / shut down. Or your network connection stopped working. Or you're just plain-old using a command incorrectly. That's what exceptions are for. They give you the opportunity to handle exceptional (ha!) circumstances properly and provide you with information what went wrong (the exception type), why it went wrong (the message), and where it went wrong (the stack trace).

Doing stuff like returning null or -1 might seem like a good idea to you, until you actually have to work with code that does that. You'll have zero information about what or why something failed in your code, and if you forget to check everything for null / -1 / whatever, you may get errors in a completely different part of your program. In essence, even with what you have in mind, you still need to write proper error handling code, Exceptions just make it much easier to do the right thing compared to an API that constantly returns error values.


Also, it would be helpful in the future if you could provide complete and detailed descriptions of the issues you encounter. For example, you mention

The code that throws this exception is in a try-catch and this try-catch is in another global try-catch

yet none of the TS3Api methods get called from within a try block, and as described above, any exceptions originating in your TimerTask will not be caught by your try-catch around Timer.scheduleAtFixedRate.

Further, you state that

As I said, the exception actually occurs with every method that the API offers to interact with clients. What else should I write about this?

yet you've not provided us with a complete stack trace of any of the exceptions you're getting. This makes it very difficult to help you find the actual root cause of the issues you're encountering.

I'd recommend you read this Jon Skeet blog entry (or at least the checklist version thereof), and, in general, try to put yourself into the shoes of someone who's responding to your question 😄

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants