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

Adding popup messages for errors with status codes alongside the exception message #2116

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
59924de
Initial commit to open PR
OhmV-IR Jan 16, 2024
2bc36cb
Added enum for status codes and function to print them
OhmV-IR Jan 17, 2024
a4afd49
Use integer enum overload
OhmV-IR Jan 18, 2024
3651990
Added project reference and status codes for NitroxConfig.cs
OhmV-IR Jan 26, 2024
cd4392c
Added error messages in a popup for nitroxModel
OhmV-IR Feb 4, 2024
4aaf86d
fix missing import statements so the solution can build
OhmV-IR Feb 4, 2024
6fb3a87
added a better messageBox dialog to display status code errors
OhmV-IR Feb 4, 2024
7488213
moved display status code enum out of nitrox server into new files in…
OhmV-IR Feb 5, 2024
6b23109
MORE FUNCTION CALLS
OhmV-IR Feb 6, 2024
60e673a
added more descriptive names for statusCodes in the files and moved s…
OhmV-IR Feb 12, 2024
e76df2f
Finished adding statusCode calls to NitroxClient
OhmV-IR Feb 12, 2024
388fd96
Check if nitroxLauncher is in a oneDrive folder implementation
OhmV-IR Feb 14, 2024
741099a
Added fatal flag to statusCode function calls
OhmV-IR Feb 20, 2024
ca8a205
Added exception message to StatusCode messageBox
OhmV-IR Feb 20, 2024
051f09a
Added exception messages to PrintStatusCode <- server status codes fu…
OhmV-IR Feb 20, 2024
df46194
Merge pull request #1 from OhmV-IR/inDev
OhmV-IR Feb 20, 2024
2a03491
removed unused isPirate bool in CustomMessagebox.cs
OhmV-IR Feb 20, 2024
9f3e552
Added test fail case for FatalStatusCodes and removed success status …
OhmV-IR Feb 20, 2024
219ef4e
Added text wrapping so that the exception message does not exceed the…
OhmV-IR Feb 21, 2024
cb86f5c
Change statusCode enum to use HTTP status codes and condense redundan…
OhmV-IR Feb 22, 2024
5ca499c
Changed enum names to follow upper snake case convention
OhmV-IR Feb 22, 2024
4a2bf7c
Changed SYNC_FAIL to use a different code than MISSING_FEATURE
OhmV-IR Feb 22, 2024
973015b
Fixed a typo that caused build errors
OhmV-IR Feb 22, 2024
a23a8ed
Added some more comments and finished unit testing, just need to play…
OhmV-IR Feb 24, 2024
f778fe1
Change enum names, use HTTP status codes, unit tests, should be ready…
OhmV-IR Feb 24, 2024
81cce0e
Client disconnects are never recognized as fatal, even if they happen…
OhmV-IR Feb 24, 2024
fc0e7dd
Merge branch 'prod-status-codes' into polishing-status-codes
OhmV-IR Feb 27, 2024
3ba4bbf
Added missing using statement
OhmV-IR Feb 27, 2024
c0b9278
Removed unneeded comments
OhmV-IR Mar 12, 2024
ace18b4
removed a useless comment
OhmV-IR Mar 17, 2024
0b542eb
Removed some usings and fixed using assemblies that had not yet been …
OhmV-IR Mar 18, 2024
1b2cb10
Merge branch 'polishing-status-codes' into master
OhmV-IR Mar 19, 2024
57b8ea2
Merge pull request #6 from OhmV-IR/master
OhmV-IR Mar 19, 2024
0137f03
Removed fatal program closes(its just bad design to end execution so …
OhmV-IR Mar 20, 2024
2baf570
Use Log.InGame for less important codes when in InDev and ignore the …
OhmV-IR Mar 20, 2024
505da81
Fixed creating release builds
OhmV-IR Mar 20, 2024
20b28f7
Changed ingame log string + removed unneeded reference in NitroxLauncher
OhmV-IR Mar 20, 2024
5a1f315
Added more function calls
OhmV-IR Mar 24, 2024
5db1930
Small fixes
OhmV-IR Mar 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added a better messageBox dialog to display status code errors
  • Loading branch information
OhmV-IR committed Feb 4, 2024
commit 6fb3a87016009ddddd71960730e41d5ce2022dab
6 changes: 4 additions & 2 deletions NitroxModel/Core/NitroxEnvironment.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System;
using System.IO;
using System.Reflection;

using static NitroxModel.DisplayStatusCodes;
using static NitroxServer.Server;
namespace NitroxModel.Helper
{
/// <summary>
Expand Down Expand Up @@ -34,6 +35,7 @@ public static void Set(Types value)
{
if (hasSet)
{
DisplayStatusCode(StatusCode.twelve);
throw new Exception("Environment type can only be set once");
}

Expand Down
8 changes: 6 additions & 2 deletions NitroxModel/Core/NitroxServiceLocator.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using System;
using Autofac;
using Autofac.Builder;
using NitroxModel.DataStructures.Util;

using static NitroxModel.DisplayStatusCodes;
using static NitroxServer.Server;
namespace NitroxModel.Core;

/// <summary>
Expand Down Expand Up @@ -39,6 +40,7 @@ public static void BeginNewLifetimeScope()
{
if (DependencyContainer == null)
{
DisplayStatusCode(StatusCode.twelve);
throw new InvalidOperationException("You must install an Autofac container before initializing a new lifetime scope.");
}

Expand Down Expand Up @@ -115,10 +117,12 @@ private static void CheckServiceResolutionViability()
{
if (DependencyContainer == null)
{
DisplayStatusCode(StatusCode.twelve);
throw new InvalidOperationException("You must install an Autofac container before resolving dependencies.");
}
if (CurrentLifetimeScope == null)
{
DisplayStatusCode(StatusCode.twelve);
throw new InvalidOperationException("You must begin a new lifetime scope before resolving dependencies.");
}
}
Expand Down
55 changes: 55 additions & 0 deletions NitroxModel/CustomMessageBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows;
using System.Windows.Forms;
using static NitroxServer.Server;
public class CustomMessageBox : Form
{
Label message = new Label();
Button helpBtn = new Button();
Button closeBtn = new Button();
public CustomMessageBox()
{

}

public CustomMessageBox(StatusCode statusCode)
{
ClientSize = new System.Drawing.Size(690, 150);
Text = "Nitrox has encountered an error!";

helpBtn.Location = new Point(611, 112);
helpBtn.Size = new Size(75, 23);
helpBtn.Text = "Help";
helpBtn.BackColor = Control.DefaultBackColor;
helpBtn.Click += HelpButtonOnClick;

closeBtn.Location = new Point(511, 112);
closeBtn.Size = new Size(75, 23);
closeBtn.Text = "Close";
closeBtn.BackColor = Control.DefaultBackColor;
closeBtn.Click += CloseButtonOnClick;

message.Location = new Point(10, 10);
message.Text = "Nitrox has run into an error with the status code " + statusCode.ToString("D") + "! " + Environment.NewLine +
"Look up this status code on the nitrox website(https://www.nitrox.rux.gg/) using the help button below for more information. " + Environment.NewLine +
"Nitrox may still be running and it is possible that Nitrox has recovered from this error. ";
message.Font = Control.DefaultFont;
message.AutoSize = true;

BackColor = Color.White;
ShowIcon = false;
Controls.Add(helpBtn);
Controls.Add(message);
}

private void HelpButtonOnClick(object sender, EventArgs e)
{
Process.Start("https://nitrox.rux.gg/");
}
private void CloseButtonOnClick(object sender, EventArgs e)
{
Close();
}
}
15 changes: 10 additions & 5 deletions NitroxModel/DataStructures/CircularBuffer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;

using static NitroxModel.DisplayStatusCodes;
using static NitroxServer.Server;
namespace NitroxModel.DataStructures;

/// <summary>
Expand All @@ -24,12 +25,16 @@ public class CircularBuffer<T> : IList<T>
{
// Proper modulus operator which C# doesn't have. % = remainder operator and doesn't work in reverse for negative numbers.
get => data[Math.Abs((index % data.Count + data.Count) % data.Count)];
set => throw new NotSupportedException();
set => throwNotSupportedException();
}

public int Count => data.Count;
public bool IsReadOnly => false;

private void throwNotSupportedException()
{
DisplayStatusCode(StatusCode.eight);
throw new NotSupportedException();
}
public CircularBuffer(int maxSize, int initialCapacity = 0)
{
if (maxSize < 0) throw new ArgumentOutOfRangeException(nameof(maxSize), "Max size must be larger than -1");
Expand All @@ -45,7 +50,7 @@ public int IndexOf(T item)

public void Insert(int index, T item)
{
throw new NotImplementedException();
throwNotSupportedException();
}

public void RemoveAt(int index)
Expand Down
6 changes: 4 additions & 2 deletions NitroxModel/DataStructures/GameLogic/AbsoluteEntityCell.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;
using NitroxModel.Core;
using NitroxModel.DataStructures.Unity;
using NitroxModel.Helper;

using static NitroxModel.DisplayStatusCodes;
using static NitroxServer.Server;
namespace NitroxModel.DataStructures.GameLogic
{
[Serializable]
Expand Down Expand Up @@ -85,6 +86,7 @@ public static int GetCellsPerBlock(int level)
case 3:
return 5;
default:
DisplayStatusCode(StatusCode.six);
throw new Exception($"Given level '{level}' does not have any defined cells.");
}
}
Expand Down
6 changes: 4 additions & 2 deletions NitroxModel/DataStructures/Optional.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Security.Permissions;

using static NitroxModel.DisplayStatusCodes;
using static NitroxServer.Server;
namespace NitroxModel.DataStructures.Util
{
/// <summary>
Expand Down Expand Up @@ -97,6 +98,7 @@ internal static Optional<T> Of(T value)
{
if (value == null)
{
DisplayStatusCode(StatusCode.eight);
throw new ArgumentNullException(nameof(value), $"Tried to set null on {typeof(Optional<T>)}");
}

Expand Down
6 changes: 4 additions & 2 deletions NitroxModel/DataStructures/PriorityQueue.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;

using static NitroxModel.DisplayStatusCodes;
using static NitroxServer.Server;
namespace NitroxModel.DataStructures
{
public class PriorityQueue<T>
Expand Down Expand Up @@ -75,6 +76,7 @@ public T Dequeue()
}
else
{
DisplayStatusCode(StatusCode.twelve);
throw new InvalidOperationException();
}
}
Expand Down
25 changes: 0 additions & 25 deletions NitroxModel/DisplayStatusCode.cs

This file was deleted.

15 changes: 15 additions & 0 deletions NitroxModel/DisplayStatusCodes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Windows.Forms;
using static NitroxServer.Server;
namespace NitroxModel
{
public class DisplayStatusCodes
{
public static void DisplayStatusCode(StatusCode statusCode)
{
CustomMessageBox customMessage = new CustomMessageBox(statusCode);
customMessage.StartPosition = FormStartPosition.CenterParent;
customMessage.ShowDialog();

}
}
}
1 change: 1 addition & 0 deletions NitroxModel/NitroxModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<Reference Include="NitroxServer">
<HintPath>..\NitroxServer\bin\Debug\NitroxServer.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="protobuf-net">
<HintPath>..\Nitrox.Assets.Subnautica\protobuf-net.dll</HintPath>
</Reference>
Expand Down
3 changes: 2 additions & 1 deletion NitroxServer-Subnautica/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
using NitroxServer;
using NitroxServer.ConsoleCommands.Processor;
using static NitroxServer.Server;

using static NitroxModel.DisplayStatusCodes;
namespace NitroxServer_Subnautica;

[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "DIMA001:Dependency Injection container is used directly")]
Expand Down Expand Up @@ -127,6 +127,7 @@ Action<string> ConsoleCommandHandler()
Log.Info("To get help for commands, run help in console or /help in chatbox");
// Log status codes that can be googled by the user to troubleshoot on their own, hopefully
PrintStatusCode(StatusCode.zero);
DisplayStatusCode(StatusCode.one);
}
}
finally
Expand Down
3 changes: 2 additions & 1 deletion NitroxServer/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public enum StatusCode
eight,
nine,
ten,
eleven
eleven,
twelve
}
public static void PrintStatusCode(StatusCode statusCode)
{
Expand Down