Skip to content

Improved Error Handling#2801

Open
lammmab wants to merge 3 commits into
SubnauticaNitrox:masterfrom
lammmab:feat/server-errors
Open

Improved Error Handling#2801
lammmab wants to merge 3 commits into
SubnauticaNitrox:masterfrom
lammmab:feat/server-errors

Conversation

@lammmab

@lammmab lammmab commented Jun 25, 2026

Copy link
Copy Markdown

Linked Issues / Context

I found no relevant issues. Feel free to tag them.

Description of Change

This PR aims to improve error output for common server errors that users may face. It took threading through a few files, and the most common error will be "Nitrox_NoResponse", but I feel it is still a great improvement over the generic "Unable to contact remote server".

Validation

  1. Build on my branch
  2. Go into game, try different server failure cases: version mismatches, no WiFi, etc.

PR Checklist

  • PR rebased on top of main at the time of opening
  • Has tests for the changes
  • Has been tested in-game (partially)

Notes

  • Some errors I could not hit testing locally. Someone with a more advanced setup will want to test all of the error cases and see if they get improved debug output.

  • I am on Arch Linux.

@lammmab
lammmab marked this pull request as draft June 25, 2026 14:57
@lammmab
lammmab marked this pull request as ready for review June 25, 2026 15:00
@Jannify

Jannify commented Jun 25, 2026

Copy link
Copy Markdown
Member

Thank you for the pr. Unfortunately I see two problems with it:

  1. We don't want to translate error messages that are written into the log file bc it makes it impossible to investigate issues for the help staff or us developers.

  2. We refrain from editing the language json files directly bc it makes it impossible for weblate to merge them. Therefore if you have new keys you can comment a list with all new keys and their English values and I will add them to the weblate where the community can translate them.

@lammmab

lammmab commented Jun 25, 2026

Copy link
Copy Markdown
Author

I had no idea. OK I will address those when I get a sec and re-open; wasn't sure of how the workflow goes so I went with what I had. So, a question: do I at least add the entry in en.json? Otherwise it will be hard to test for english speakers. That's all I need to know.

@lammmab
lammmab marked this pull request as draft June 25, 2026 16:15
@Jannify

Jannify commented Jun 25, 2026

Copy link
Copy Markdown
Member

I had no idea. OK I will address those when I get a sec and re-open; wasn't sure of how the workflow goes so I went with what I had. So, a question: do I at least add the entry in en.json? Otherwise it will be hard to test for english speakers. That's all I need to know.

You can leave it in for testing but before merging to master it needs to be removed.

@lammmab

lammmab commented Jun 25, 2026

Copy link
Copy Markdown
Author

So then how do we know what string to translate to other languages? Can I go into weblate and add the english translation myself? Apologies for not understanding here; I've never worked with a project including translations before.

_ => ex.Message
};

Log.ErrorSensitive("Unable to contact remote server: {ip}:{port}. {reason}", serverIp, serverPort, ex.Message);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now English, ex.Message is the English error before translation.

"Nitrox_TeleportToQuestion": "Teleport to {PLAYER}?",
"Nitrox_ThankForPlaying": "Thanks for using Nitrox!",
"Nitrox_UnableToConnect": "Unable to contact the remote server at:",
"Nitrox_NoConnection": "No network connection available.",

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be changed before merge. For now, I will keep it so we have reference strings.

@lammmab

lammmab commented Jun 25, 2026

Copy link
Copy Markdown
Author

I had no idea. OK I will address those when I get a sec and re-open; wasn't sure of how the workflow goes so I went with what I had. So, a question: do I at least add the entry in en.json? Otherwise it will be hard to test for english speakers. That's all I need to know.

You can leave it in for testing but before merging to master it needs to be removed.

OK, I have made both changes you requested. 👍

@lammmab
lammmab marked this pull request as ready for review June 25, 2026 23:25
@lammmab lammmab changed the title Improved Error Handling & All Translations Improved Error Handling Jun 26, 2026
@dartasen
dartasen requested a review from Jannify July 3, 2026 21:13
if (endpoint == null)
{
Log.InGame($"{Language.main.Get("Nitrox_UnableToConnect")}: {serverIp}:{serverPort}");
Log.InGame($"{Language.main.Get("Nitrox_ServerNotFound")}: {serverIp}:{serverPort}");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference in the Nitrox_UnableToConnect message vs the new Nitrox_ServerNotFound? Isn't it technically the same outcome?


IsConnected = false;
Log.Info("Disconnected from server");
Log.Error($"Disconnected from server. Reason: {disconnectInfo.Reason}, SocketError: {disconnectInfo.SocketErrorCode}");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we log an error if we disconnected gracefully?

Comment on lines +29 to +30
private DisconnectInfo? lastDisconnectInfo;
public DisconnectInfo? ConnectFailReason => lastDisconnectInfo;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Would maybe compact it into a property. Right now the both names convey different meaning of the "same" variable.

Comment on lines +2 to +3
using System.Net.NetworkInformation;
using System.Linq;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong sorting

&& n.NetworkInterfaceType != NetworkInterfaceType.Loopback
&& n.NetworkInterfaceType != NetworkInterfaceType.Tunnel))
{
throw new ClientConnectionFailedException(Language.main.Get("Nitrox_NoConnection"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In every case in this file where we translate the message in the constructor we will be logging it translated in the logs, or am I wrong?

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

Successfully merging this pull request may close these issues.

2 participants