jagrosh / jagrosh/MusicBot

[Bug Report] No handling for no internet connection

Open
#1,303 1 comment 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
5.8k
Forks
2.8k
PR merge metrics
No merged PRs in 30d

Description

### Bug Description

When running the bot without an internet connection, the JDA connection attempt will fail without catching the exception and doing a proper system exit. When a server (physical PC) running the bot restarts, if there is no internet connection when the system starts, the bot will fail without crashing and therefore cannot be restarted automatically.

`[06:02:09] [ERROR] [Requester]: DNS resolution failed: discord.com: Name or service not known
Exception in thread "main" net.dv8tion.jda.api.exceptions.ErrorResponseException: -1: java.net.UnknownHostException
at net.dv8tion.jda.internal.requests.RestActionImpl.complete(RestActionImpl.java:227)
at net.dv8tion.jda.api.requests.RestAction.complete(RestAction.java:633)
at net.dv8tion.jda.api.utils.SessionControllerAdapter.getGateway(SessionControllerAdapter.java:86)
at net.dv8tion.jda.internal.JDAImpl.getGateway(JDAImpl.java:318)
at net.dv8tion.jda.internal.JDAImpl.login(JDAImpl.java:276)
at net.dv8tion.jda.internal.JDAImpl.login(JDAImpl.java:268)
at net.dv8tion.jda.api.JDABuilder.build(JDABuilder.java:1874)
at com.jagrosh.jmusicbot.JMusicBot.startBot(JMusicBot.java:187)
at com.jagrosh.jmusicbot.JMusicBot.main(JMusicBot.java:65)
Caused by: java.net.UnknownHostException: discord.com: Name or service not known

...

Caused by: net.dv8tion.jda.api.exceptions.ContextException
at net.dv8tion.jda.api.exceptions.ContextException.here(ContextException.java:54)
at net.dv8tion.jda.api.requests.Request.(Request.java:71)
at net.dv8tion.jda.api.requests.RestFuture.(RestFuture.java:36)
at net.dv8tion.jda.internal.requests.RestActionImpl.submit(RestActionImpl.java:209)
at net.dv8tion.jda.internal.requests.RestActionImpl.complete(RestActionImpl.java:219)
at net.dv8tion.jda.api.requests.RestAction.complete(RestAction.java:633)
at net.dv8tion.jda.api.utils.SessionControllerAdapter.getGateway(SessionControllerAdapter.java:86)
at net.dv8tion.jda.internal.JDAImpl.getGateway(JDAImpl.java:318)
at net.dv8tion.jda.internal.JDAImpl.login(JDAImpl.java:276)
at net.dv8tion.jda.internal.JDAImpl.login(JDAImpl.java:268)
at net.dv8tion.jda.api.JDABuilder.build(JDABuilder.java:1874)
at com.jagrosh.jmusicbot.JMusicBot.startBot(JMusicBot.java:187)
at com.jagrosh.jmusicbot.JMusicBot.main(JMusicBot.java:65)`

### Steps to Reproduce

1. Start the bot without an internet connection

### Expected Result

I expect the bot to system exit if launched with no internet connection

### Debug Output

OS: Debian GNU/Linux 11 (bullseye)
JMusicBot: 0.3.8

### Additional Info

_No response_

### Checklist

- [X] I have looked for information about this [within the documentation](https://jmusicbot.com/)
- [X] I have searched for similar issues [on the issues page](https://github.com/jagrosh/MusicBot/issues?q=is%3Aissue)
- [X] I am running the latest version of the bot: ![Release](https://img.shields.io/github/release/jagrosh/MusicBot.svg)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in JMusicBot.java at the startBot and main entry points shown in the stack trace, and trace the connection attempt made during startup. Reproduce the launch without an internet connection and verify that the bot exits with the expected failure behavior so an automatic restart can occur.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, networking
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.