fix: Properly rethrow non-deterministic exceptions

Doing `throw <myExceptionVariable>` causes the stack trace information
to be rewritten (we don't want this). Wrapping in a new exception object
like `AggregateException` fixes that but also makes the printed
exception look messier.

Instead, simply return a bool to indicate if `HandleException()`
processed the the exception; if not, then we can rethrow from outside
the method.
pull/231/head
Robert Dailey 12 months ago
parent 833161efce
commit 8bf205f171

@ -61,7 +61,12 @@ public class DeleteCustomFormatsCommand : AsyncCommand<DeleteCustomFormatsComman
}
catch (Exception e)
{
await _exceptionHandler.HandleException(e);
if (!await _exceptionHandler.HandleException(e))
{
// This means we didn't handle the exception; rethrow it.
throw;
}
return (int) ExitStatus.Failed;
}

@ -18,7 +18,7 @@ public class ConsoleExceptionHandler
_httpExceptionHandler = httpExceptionHandler;
}
public async Task HandleException(Exception sourceException)
public async Task<bool> HandleException(Exception sourceException)
{
switch (sourceException)
{
@ -65,9 +65,10 @@ public class ConsoleExceptionHandler
_log.Error(e.Message);
break;
// This handles non-deterministic/unexpected exceptions.
default:
throw sourceException;
return false;
}
return true;
}
}

@ -6,8 +6,8 @@ namespace Recyclarr.Cli.Processors;
[Serializable]
public class FatalException : Exception
{
public FatalException(string? message)
: base(message)
public FatalException(string? message, Exception? innerException = null)
: base(message, innerException)
{
}

@ -51,7 +51,12 @@ public class SyncProcessor : ISyncProcessor
}
catch (Exception e)
{
await _exceptionHandler.HandleException(e);
if (!await _exceptionHandler.HandleException(e))
{
// This means we didn't handle the exception; rethrow it.
throw;
}
failureDetected = true;
}
@ -73,7 +78,12 @@ public class SyncProcessor : ISyncProcessor
}
catch (Exception e)
{
await _exceptionHandler.HandleException(e);
if (!await _exceptionHandler.HandleException(e))
{
// This means we didn't handle the exception; rethrow it.
throw;
}
failureDetected = true;
}
}

Loading…
Cancel
Save