Other Diagnostics
Diagnosing the kernel the other way!
Last updated
Diagnosing the kernel the other way!
Last updated
There are various diagnostic tools that the kernel can make use of, including those listed below.
This is internally used by the kernel debugger and the kernel exception to allow getting information about the source code that generated the call. Currently, this information is provided:
Method name: The routine name that made a call to the class constructor
Line number: The line number of the method described above
Column number: The column number found within the line
File name: The file name of the class that the method situates
When the constructor is called, it generates information about the third stack frame to get the caller's method info. If the frame number is specified, it gets offset by +1
to get info about the needed method.
This method is internally called by the debug writer. If you really want to create an instance of this class, you'll have to use Reflection. The class name is DebugStackFrame
in the Nitrocid.Kernel.Debugging.Trace
namespace.
In the event that the kernel reported a kernel panic in all of the types, whether continuable or uncontinuable, the kernel dump file will be generated under the name of dmp_date_time.txt
in the kernel configuration directory. These files assist us in debugging the severe kernel crashes in case the bug involves this event.
This file includes the following information:
Kernel error code
Error description
In-depth analysis of the error
Stack trace
Nitrocid kernel threads
OS threads spawned by Nitrocid
Threads' backtraces
Version information
The kernel error codes are listed below from the least severe to the most severe:
C
: Indicates that the kernel error is minor, but still serious
S
: Serious kernel error
F
: Fatal kernel error
U
: Unrecoverable kernel error
The first-chance kernel errors of the above types are the first failures. During the error handling, if it encountered a second failure, it escalates the severity of the error to the double panic. Finally, if the double panic handler experiences a third fault, the host operating system will force the kernel to exit.
In case of the third failure events, you can find the event in the Application Events within the Event Viewer if running on Windows or the error directly dumped to the application on Linux.
The kernel exceptions are just normal errors with a generic message intended to display extended information about the error the kernel is experiencing. The kernel exception types and their messages are typically found in this file:
To make a kernel exception, throw a new instance of KernelException
found in the Nitrocid.Kernel.Exceptions
namespace in one of the forms:
public KernelException(KernelExceptionType exceptionType)
public KernelException(KernelExceptionType exceptionType, Exception e)
public KernelException(KernelExceptionType exceptionType, string message)
public KernelException(KernelExceptionType exceptionType, string message, params object[] vars)
public KernelException(KernelExceptionType exceptionType, string message, Exception e)
public KernelException(KernelExceptionType exceptionType, string message, Exception e, params object[] vars)
Typically, the message displays the exception type, the message, and the exception information. As always, if you believe that it's a bug, make an issue in our GitHub repository.
The debug shell allows you to diagnose the kernel in depth. The following commands are available in the below page:
Additionally, the same command will not work on Android devices and will fail with this error:
Microsoft.Diagnostics.NETCore.Client.ServerNotAvailableException: Process [pid] not running compatible .NET runtime.
If you're running on Windows 7, threadsbt
is not going to work due to how it uses the Windows API function, which is first introduced on Windows 8.1, which makes this operating system a minimum requirement for using this command.
//
// Nitrocid KS Copyright (C) 2018-2025 Aptivi
//
// This file is part of Nitrocid KS
//
// Nitrocid KS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Nitrocid KS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY, without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
using Nitrocid.Kernel.Debugging;
using Nitrocid.Languages;
using System;
using System.Collections.Generic;
using System.Text;
using Textify.General;
namespace Nitrocid.Kernel.Exceptions
{
internal static class KernelExceptionMessages
{
internal static Dictionary<KernelExceptionType, string> Messages =>
new()
{
{ KernelExceptionType.Unknown, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_UNKNOWN") },
{ KernelExceptionType.AliasAlreadyExists, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_ALIASALREADYEXISTS") },
{ KernelExceptionType.AliasInvalidOperation, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_ALIASINVALIDOPERATION") },
{ KernelExceptionType.AliasNoSuchAlias, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_ALIASNOSUCHALIAS") },
{ KernelExceptionType.AliasNoSuchCommand, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_ALIASNOSUCHCOMMAND") },
{ KernelExceptionType.AliasNoSuchType, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_ALIASNOSUCHTYPE") },
{ KernelExceptionType.Color, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_COLOR") },
{ KernelExceptionType.Config, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_CONFIG") },
{ KernelExceptionType.ConsoleReadTimeout, LanguageTools.GetLocalized("NKS_DRIVERS_INPUT_BASE_EXCEPTION_INPUTTIMEOUT") },
{ KernelExceptionType.Filesystem, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_FILESYSTEM") },
{ KernelExceptionType.FTPFilesystem, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_FTPFILESYSTEM") },
{ KernelExceptionType.FTPNetwork, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_FTPNETWORK") },
{ KernelExceptionType.FTPShell, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_FTPSHELL") },
{ KernelExceptionType.GroupManagement, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_GROUPMANAGEMENT") },
{ KernelExceptionType.Hostname, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_HOSTNAME") },
{ KernelExceptionType.HTTPShell, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_HTTPSHEL") },
{ KernelExceptionType.InsaneConsoleDetected, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_INSANECONSOLEDETECTED") },
{ KernelExceptionType.InvalidFeed, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_INVALIDFEED") },
{ KernelExceptionType.InvalidFeedLink, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_INVALIDFEEDLINK") },
{ KernelExceptionType.InvalidFeedType, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_INVALIDFEEDTYPE") },
{ KernelExceptionType.InvalidHashAlgorithm, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_INVALIDHASHALGORITHM") },
{ KernelExceptionType.InvalidHash, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_INVALIDHASHSUM") },
{ KernelExceptionType.InvalidKernelPath, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_INVALIDKERNELPATH") },
{ KernelExceptionType.InvalidManpage, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_INVALIDMANPAGE") },
{ KernelExceptionType.InvalidMod, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_INVALIDMOD") },
{ KernelExceptionType.InvalidPath, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_INVALIDPATH") },
{ KernelExceptionType.InvalidPlaceholder, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_INVALIDPLACEHOLDER") },
{ KernelExceptionType.LanguageInstall, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_LANGUAGEINSTALL") },
{ KernelExceptionType.LanguageParse, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_LANGUAGELOAD") },
{ KernelExceptionType.LanguageUninstall, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_LANGUAGEUNINSTALL") },
{ KernelExceptionType.Mail, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_MAIL") },
{ KernelExceptionType.ModInstall, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_MODINSTALL") },
{ KernelExceptionType.ModWithoutMod, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_MODWITHOUTMOD") },
{ KernelExceptionType.ModUninstall, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_MODUNINSTALL") },
{ KernelExceptionType.MOTD, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_MOTD") },
{ KernelExceptionType.NoSuchEvent, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_NOSUCHEVENT") },
{ KernelExceptionType.NoSuchLanguage, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_NOSUCHLANGUAGE") },
{ KernelExceptionType.NoSuchMailDirectory, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_NOSUCHMODDIRECTORY") },
{ KernelExceptionType.NoSuchMod, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_NOSUCHMOD") },
{ KernelExceptionType.NoSuchReflectionProperty, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_NOSUCHREFLECTIONPROPERTY") },
{ KernelExceptionType.NoSuchReflectionVariable, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_NOSUCHREFLECTIONVARIABLE") },
{ KernelExceptionType.NoSuchScreensaver, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_NOSUCHSCREENSAVER") },
{ KernelExceptionType.NoSuchShellPreset, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_NOSUCHSHELLPRESET") },
{ KernelExceptionType.NoSuchTheme, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_NOSUCHTHEME") },
{ KernelExceptionType.NullUsers, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_NULLUSERS") },
{ KernelExceptionType.PermissionManagement, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_PERMISSIONMANAGEMENT") },
{ KernelExceptionType.RemoteDebugDeviceAlreadyExists, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_REMOTEDEBUGDEVICEALREADYEXISTS") },
{ KernelExceptionType.RemoteDebugDeviceNotFound, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_REMOTEDEBUGDEVICENOTFOUND") },
{ KernelExceptionType.RemoteDebugDeviceOperation, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_REMOTEDEBUGDEVICEOPERATION") },
{ KernelExceptionType.RSSNetwork, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_RSSNETWORK") },
{ KernelExceptionType.RSSShell, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_RSSSHELL") },
{ KernelExceptionType.ScreensaverManagement, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_SCREENSAVERMANAGEMENT") },
{ KernelExceptionType.SFTPFilesystem, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_SFTPFILESYSTEM") },
{ KernelExceptionType.SFTPNetwork, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_SFTPNETWORK") },
{ KernelExceptionType.SFTPShell, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_SFTPSHELL") },
{ KernelExceptionType.UESHConditionParse, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_UESHCONDITIONPARSE") },
{ KernelExceptionType.UESHScript, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_UESHSCRIPT") },
{ KernelExceptionType.UserCreation, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_USERCREATION") },
{ KernelExceptionType.UserManagement, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_USERMANAGEMENT") },
{ KernelExceptionType.Network, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_NETWORK") },
{ KernelExceptionType.UnsupportedConsole, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_UNSUPPORTEDCONSOLE") },
{ KernelExceptionType.AssertionFailure, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_ASSERTIONFAILURE") },
{ KernelExceptionType.NetworkOffline, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_NETWORKOFFLINE") },
{ KernelExceptionType.PermissionDenied, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_PERMISSIONDENIED") },
{ KernelExceptionType.NoSuchUser, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_NOSUCHUSER") },
{ KernelExceptionType.NoSuchDriver, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_NOSUCHDRIVER") },
{ KernelExceptionType.ThreadNotReadyYet, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_THREADNOTREADYYET") },
{ KernelExceptionType.ThreadOperation, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_THREADOPERATION") },
{ KernelExceptionType.ShellOperation, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_SHELLOPERATION") },
{ KernelExceptionType.NotImplementedYet, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_NOTIMPLEMENTEDYET") },
{ KernelExceptionType.RemoteProcedure, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_REMOTEPROCEDURE") },
{ KernelExceptionType.Encryption, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_ENCRYPTION") },
{ KernelExceptionType.Debug, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_DEBUG") },
{ KernelExceptionType.Archive, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_ARCHIVE") },
{ KernelExceptionType.HexEditor, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_HEXEDITOR") },
{ KernelExceptionType.JsonEditor, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_JSONEDITOR") },
{ KernelExceptionType.TextEditor, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_TEXTEDITOR") },
{ KernelExceptionType.OldModDetected, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_OLDMODDETECTED") },
{ KernelExceptionType.RegularExpression, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_REGULAREXPRESSION") },
{ KernelExceptionType.Contacts, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_CONTACTS") },
{ KernelExceptionType.UESHConditional, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_UESHCONDITIONAL") },
{ KernelExceptionType.SqlEditor, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_SQLEDITOR") },
{ KernelExceptionType.NoSuchGroup, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_NOSUCHGROUP") },
{ KernelExceptionType.InteractiveTui, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_INTERACTIVETUI") },
{ KernelExceptionType.CustomSettings, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_CUSTOMSETTINGS") },
{ KernelExceptionType.NetworkConnection, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_NETWORKCONNECTION") },
{ KernelExceptionType.HTTPNetwork, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_HTTPNETWORK") },
{ KernelExceptionType.CommandManager, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_COMMANDMANAGER") },
{ KernelExceptionType.LocaleGen, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_LOCALEGEN") },
{ KernelExceptionType.TimeDate, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_TIMEDATE") },
{ KernelExceptionType.ModManual, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_MODMANUAL") },
{ KernelExceptionType.Calendar, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_CALENDAR") },
{ KernelExceptionType.NotificationManagement, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_NOTIFICATIONMANAGEMENT") },
{ KernelExceptionType.LanguageManagement, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_LANGUAGEMANAGEMENT") },
{ KernelExceptionType.ModManagement, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_MODMANAGEMENT") },
{ KernelExceptionType.Reflection, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_REFLECTION") },
{ KernelExceptionType.ThemeManagement, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_THEMEMANAGEMENT") },
{ KernelExceptionType.EventManagement, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_EVENTMANAGEMENT") },
{ KernelExceptionType.AddonManagement, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_ADDONMANAGEMENT") },
{ KernelExceptionType.NoteManagement, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_NOTEMANAGEMENT") },
{ KernelExceptionType.Hardware, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_HARDWARE") },
{ KernelExceptionType.LoginHandler, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_LOGINHANDLER") },
{ KernelExceptionType.Encoding, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_ENCODING") },
{ KernelExceptionType.PrivacyConsent, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_PRIVACYCONSENT") },
{ KernelExceptionType.Splash, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_SPLASH") },
{ KernelExceptionType.Text, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_TEXT") },
{ KernelExceptionType.InvalidPlaceholderAction, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_INVALIDPLACEHOLDERACTION") },
{ KernelExceptionType.DriverHandler, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_DRIVERHANDLER") },
{ KernelExceptionType.ProgressHandler, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_PROGRESSHANDLER") },
{ KernelExceptionType.Console, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_CONSOLE") },
{ KernelExceptionType.Journaling, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_JOURNALING") },
{ KernelExceptionType.Docking, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_DOCKING") },
{ KernelExceptionType.Security, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_SECURITY") },
{ KernelExceptionType.DriverManagement, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_DRIVERMANAGEMENT") },
{ KernelExceptionType.Environment, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_ENVIRONMENT") },
{ KernelExceptionType.Bootloader, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_BOOTLOADER") },
{ KernelExceptionType.Alarm, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_ALARM") },
{ KernelExceptionType.Widget, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_WIDGET") },
{ KernelExceptionType.Homepage, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_HOMEPAGE") },
{ KernelExceptionType.NoSuchCulture, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_NOSUCHCULTURE") },
{ KernelExceptionType.AudioCue, LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_MESSAGE_AUDIOCUE") },
};
internal static string GetFinalExceptionMessage(KernelExceptionType exceptionType, string message, Exception? e, params object[] vars)
{
StringBuilder builder = new();
// Display introduction
DebugWriter.WriteDebug(DebugLevel.I, "Not a nested KernelException.");
builder.AppendLine(LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_FINALEXCEPTION_INTRO"));
builder.AppendLine();
// Display error type
builder.AppendLine("--- " + LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_FINALEXCEPTION_EXCEPTIONINFO") + " ---");
builder.AppendLine("- " + LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_FINALEXCEPTION_ERRORTYPE") + $": {exceptionType} [{Convert.ToInt32(exceptionType)}]");
builder.AppendLine(" " + LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_FINALEXCEPTION_ERRORMESSAGE") + $": {GetMessageFromType(exceptionType)}");
builder.AppendLine();
// Display error message
builder.AppendLine("--- " + LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_FINALEXCEPTION_ADDIITONALINFO") + " ---");
DebugWriter.WriteDebug(DebugLevel.I, "Error message \"{0}\"", vars: [message]);
if (!string.IsNullOrWhiteSpace(message))
{
builder.AppendLine("- " + LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_FINALEXCEPTION_HASINFO"));
builder.AppendLine(" " + TextTools.FormatString(message, vars));
}
else
builder.AppendLine("- " + LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_FINALEXCEPTION_HASNOINFO"));
builder.AppendLine();
// Display exception
builder.AppendLine("--- " + LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_FINALEXCEPTION_EXCEPTIONDETAILS") + " ---");
DebugWriter.WriteDebug(DebugLevel.I, "Exception is not null: {0}", vars: [e is not null]);
if (e is not null)
{
builder.AppendLine("- " + LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_FINALEXCEPTION_ADDIITONALINFO1"));
builder.AppendLine(" " + $"{e.GetType().Name}: {(e is KernelException kex ? kex.OriginalExceptionMessage : e.Message)}");
}
else
builder.AppendLine("- " + LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_FINALEXCEPTION_HASNOEXCEPTIONINFO"));
builder.AppendLine();
// Display inner exceptions
builder.AppendLine("--- " + LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_FINALEXCEPTION_INNEREXCEPTION") + " ---");
int exceptionIndex = 1;
if (e is not null)
e = e.InnerException;
if (e is not null)
builder.AppendLine("- " + LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_FINALEXCEPTION_ADDIITONALERRORS"));
while (e is not null)
{
DebugWriter.WriteDebug(DebugLevel.I, "Inner exception {0} is not null: {1}", vars: [exceptionIndex, e is not null]);
builder.AppendLine(" " + $"[{exceptionIndex}] {e?.GetType().Name}: {(e is KernelException kex ? kex.OriginalExceptionMessage : e?.Message)}");
e = e?.InnerException;
exceptionIndex++;
}
if (e is null)
builder.AppendLine("- " + LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_FINALEXCEPTION_ADDITIONALERRORS"));
builder.AppendLine();
builder.Append(LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_FINALEXCEPTION_OUTRO"));
return builder.ToString();
}
internal static string GetMessageFromType(KernelExceptionType exceptionType) =>
Messages.TryGetValue(exceptionType, out string? type) ?
type :
LanguageTools.GetLocalized("NKS_KERNEL_EXCEPTIONS_FINALEXCEPTION_INVALIDTYPE");
}
}