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

[Neo CLI Optimization] fix exception message #3314

Merged
merged 10 commits into from
Jun 14, 2024
49 changes: 43 additions & 6 deletions src/Neo.CLI/CLI/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
using System.Net;
using System.Numerics;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -377,17 +378,42 @@
CustomApplicationSettings(options, Settings.Default);
try
{
NeoSystem = new NeoSystem(protocol, Settings.Default.Storage.Engine, string.Format(Settings.Default.Storage.Path, protocol.Network.ToString("X8")));
NeoSystem = new NeoSystem(protocol, Settings.Default.Storage.Engine,
string.Format(Settings.Default.Storage.Path, protocol.Network.ToString("X8")));
}
catch (DllNotFoundException ex) when (ex.Message.Contains("libleveldb"))
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
if (File.Exists("libleveldb.dll"))
{
DisplayError("Dependency DLL not found, please install Microsoft Visual C++ Redistributable.",
"See https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist");
}
else
{
DisplayError("DLL not found, please get libleveldb.dll.");
}
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
DisplayError("Shared library libleveldb.dylib not found, please get libleveldb.dylib.",
"From https://github.com/neo-project/neo/releases");
}
else
{
DisplayError("Neo CLI is broken, please reinstall it.",
"From https://github.com/neo-project/neo/releases");
}

}
catch (DllNotFoundException)
{
ConsoleHelper.Error("DLL not found, please install Microsoft Visual C++ Redistributable." + Environment.NewLine +
"See https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist" + Environment.NewLine +
"Press any key to exit.");
Console.ReadKey();
Environment.Exit(-1);
DisplayError("Neo CLI is broken, please reinstall it.",
"From https://github.com/neo-project/neo/releases");
}

NeoSystem.AddService(this);

Check warning on line 416 in src/Neo.CLI/CLI/MainService.cs

View workflow job for this annotation

GitHub Actions / Format

Dereference of a possibly null reference.

Check warning on line 416 in src/Neo.CLI/CLI/MainService.cs

View workflow job for this annotation

GitHub Actions / Format

Dereference of a possibly null reference.

LocalNode = NeoSystem.LocalNode.Ask<LocalNode>(new LocalNode.GetInstance()).Result;

Expand Down Expand Up @@ -459,6 +485,17 @@
ConsoleHelper.Error(ex.GetBaseException().Message);
}
}

return;

void DisplayError(string primaryMessage, string? secondaryMessage = null)
{
ConsoleHelper.Error(primaryMessage + Environment.NewLine +
(secondaryMessage != null ? secondaryMessage + Environment.NewLine : "") +
"Press any key to exit.");
Console.ReadKey();
Environment.Exit(-1);
}
}

public void Stop()
Expand Down