improve error message reporting in romloader

fixes #2320
This commit is contained in:
nattthebear 2020-08-22 15:24:17 -04:00
parent 8499f54127
commit fb6924bd83
1 changed files with 45 additions and 30 deletions

View File

@ -677,23 +677,46 @@ namespace BizHawk.Client.Common
{ {
var system = game?.System; var system = game?.System;
DispatchErrorMessage(ex, system);
return false;
}
Rom = rom;
LoadedEmulator = nextEmulator;
Game = game;
return true;
}
private void DispatchErrorMessage(Exception ex, string system)
{
if (ex is AggregateException agg)
{
// all cores failed to load a game, so tell the user everything that went wrong and maybe they can fix it
if (agg.InnerExceptions.Count > 1)
{
DoLoadErrorCallback("Multiple cores failed to load the rom:", system);
}
foreach (Exception e in agg.InnerExceptions)
{
DispatchErrorMessage(e, system);
}
return;
}
// all of the specific exceptions we're trying to catch here aren't expected to have inner exceptions, // all of the specific exceptions we're trying to catch here aren't expected to have inner exceptions,
// so drill down in case we got a TargetInvocationException or something like that // so drill down in case we got a TargetInvocationException or something like that
while (ex.InnerException != null) while (ex.InnerException != null)
ex = ex.InnerException; ex = ex.InnerException;
// Specific hack here, as we get more cores of the same system, this isn't scalable
if (ex is MissingFirmwareException) if (ex is MissingFirmwareException)
{ {
DoLoadErrorCallback(ex.Message, system, path, Deterministic, LoadErrorType.MissingFirmware); DoLoadErrorCallback(ex.Message, system, LoadErrorType.MissingFirmware);
} }
else if (ex is CGBNotSupportedException) else if (ex is CGBNotSupportedException)
{ {
// failed to load SGB bios or game does not support SGB mode. // failed to load SGB bios or game does not support SGB mode.
// To avoid catch-22, disable SGB mode DoLoadErrorCallback("Failed to load a GB rom in SGB mode. You might try disabling SGB Mode.", system);
_config.GbAsSgb = false;
DoMessageCallback("Failed to load a GB rom in SGB mode. Disabling SGB Mode.");
return LoadRom(path, nextComm, launchLibretroCore, recursiveCount + 1);
} }
else if (ex is NoAvailableCoreException) else if (ex is NoAvailableCoreException)
{ {
@ -704,14 +727,6 @@ namespace BizHawk.Client.Common
{ {
DoLoadErrorCallback($"A core accepted the rom, but threw an exception while loading it:\n\n{ex}", system); DoLoadErrorCallback($"A core accepted the rom, but threw an exception while loading it:\n\n{ex}", system);
} }
return false;
}
Rom = rom;
LoadedEmulator = nextEmulator;
Game = game;
return true;
} }
/// <remarks>TODO add and handle <see cref="FilesystemFilter.LuaScripts"/> (you can drag-and-drop scripts and there are already non-rom things in this list, so why not?)</remarks> /// <remarks>TODO add and handle <see cref="FilesystemFilter.LuaScripts"/> (you can drag-and-drop scripts and there are already non-rom things in this list, so why not?)</remarks>