Skip to content

Commit

Permalink
improve error message reporting in romloader
Browse files Browse the repository at this point in the history
fixes #2320
  • Loading branch information
nattthebear committed Aug 22, 2020
1 parent 8499f54 commit fb6924b
Showing 1 changed file with 44 additions and 29 deletions.
73 changes: 44 additions & 29 deletions src/BizHawk.Client.Common/RomLoader.cs
Expand Up @@ -25,7 +25,7 @@ private class DiscAsset : IDiscAsset
public Disc DiscData { get; set; }
public DiscType DiscType { get; set; }
public string DiscName { get; set; }
}
}
private class RomAsset : IRomAsset
{
public byte[] RomData { get; set; }
Expand Down Expand Up @@ -312,7 +312,7 @@ private bool LoadDisc(string path, CoreComm nextComm, HawkFile file, string ext,
{
Comm = nextComm,
Game = game,
Discs =
Discs =
{
new DiscAsset
{
Expand Down Expand Up @@ -677,41 +677,56 @@ public bool LoadRom(string path, CoreComm nextComm, string launchLibretroCore, i
{
var system = game?.System;

// 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
while (ex.InnerException != null)
ex = ex.InnerException;
DispatchErrorMessage(ex, system);
return false;
}

// Specific hack here, as we get more cores of the same system, this isn't scalable
if (ex is MissingFirmwareException)
{
DoLoadErrorCallback(ex.Message, system, path, Deterministic, LoadErrorType.MissingFirmware);
}
else if (ex is CGBNotSupportedException)
{
// failed to load SGB bios or game does not support SGB mode.
// To avoid catch-22, disable SGB mode
_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)
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)
{
// handle exceptions thrown by the new detected systems that BizHawk does not have cores for
DoLoadErrorCallback($"{ex.Message}\n\n{ex}", system);
DoLoadErrorCallback("Multiple cores failed to load the rom:", system);
}
else
foreach (Exception e in agg.InnerExceptions)
{
DoLoadErrorCallback($"A core accepted the rom, but threw an exception while loading it:\n\n{ex}", system);
DispatchErrorMessage(e, system);
}

return false;
return;
}

Rom = rom;
LoadedEmulator = nextEmulator;
Game = game;
return true;
// 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
while (ex.InnerException != null)
ex = ex.InnerException;

if (ex is MissingFirmwareException)
{
DoLoadErrorCallback(ex.Message, system, LoadErrorType.MissingFirmware);
}
else if (ex is CGBNotSupportedException)
{
// failed to load SGB bios or game does not support SGB mode.
DoLoadErrorCallback("Failed to load a GB rom in SGB mode. You might try disabling SGB Mode.", system);
}
else if (ex is NoAvailableCoreException)
{
// handle exceptions thrown by the new detected systems that BizHawk does not have cores for
DoLoadErrorCallback($"{ex.Message}\n\n{ex}", system);
}
else
{
DoLoadErrorCallback($"A core accepted the rom, but threw an exception while loading it:\n\n{ex}", system);
}
}

/// <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>
Expand Down

0 comments on commit fb6924b

Please sign in to comment.