mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
IException, GenericException
Adds ability to wrap an existing exception and push it through the pipe
This commit is contained in:
parent
adbddfa16e
commit
2c47f54752
@ -6,10 +6,11 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Wabbajack.Common.StatusFeed
|
namespace Wabbajack.Common.StatusFeed
|
||||||
{
|
{
|
||||||
public abstract class AErrorMessage : Exception, IError
|
public abstract class AErrorMessage : Exception, IException
|
||||||
{
|
{
|
||||||
public DateTime Timestamp { get; } = DateTime.Now;
|
public DateTime Timestamp { get; } = DateTime.Now;
|
||||||
public abstract string ShortDescription { get; }
|
public abstract string ShortDescription { get; }
|
||||||
public abstract string ExtendedDescription { get; }
|
public abstract string ExtendedDescription { get; }
|
||||||
|
Exception IException.Exception => this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
Wabbajack.Common/StatusFeed/Errors/GenericException.cs
Normal file
27
Wabbajack.Common/StatusFeed/Errors/GenericException.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Wabbajack.Common.StatusFeed.Errors
|
||||||
|
{
|
||||||
|
public class GenericException : IException
|
||||||
|
{
|
||||||
|
public string ExtraMessage { get; }
|
||||||
|
|
||||||
|
public DateTime Timestamp { get; } = DateTime.Now;
|
||||||
|
|
||||||
|
public string ShortDescription => ExtraMessage ?? Exception?.Message;
|
||||||
|
|
||||||
|
public string ExtendedDescription => $"{ExtraMessage}: {Exception?.ToString()}";
|
||||||
|
|
||||||
|
public Exception Exception { get; }
|
||||||
|
|
||||||
|
public GenericException(Exception exception, string extraMessage = null)
|
||||||
|
{
|
||||||
|
ExtraMessage = extraMessage;
|
||||||
|
Exception = exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
13
Wabbajack.Common/StatusFeed/IException.cs
Normal file
13
Wabbajack.Common/StatusFeed/IException.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Wabbajack.Common.StatusFeed
|
||||||
|
{
|
||||||
|
public interface IException : IError
|
||||||
|
{
|
||||||
|
Exception Exception { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -63,31 +63,23 @@ namespace Wabbajack.Common
|
|||||||
|
|
||||||
public static T Log<T>(T msg) where T : IStatusMessage
|
public static T Log<T>(T msg) where T : IStatusMessage
|
||||||
{
|
{
|
||||||
lock (_lock)
|
LogToFile(msg.ShortDescription);
|
||||||
{
|
|
||||||
File.AppendAllText(LogFile, msg + "\r\n");
|
|
||||||
}
|
|
||||||
LoggerSubj.OnNext(msg);
|
LoggerSubj.OnNext(msg);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Error(AErrorMessage err)
|
public static void Error(IException err)
|
||||||
{
|
{
|
||||||
lock (_lock)
|
LogToFile(err.ShortDescription);
|
||||||
{
|
|
||||||
File.AppendAllText(LogFile, err.ShortDescription + "\r\n");
|
|
||||||
}
|
|
||||||
LoggerSubj.OnNext(err);
|
LoggerSubj.OnNext(err);
|
||||||
throw err;
|
throw err.Exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LogToFile(string msg)
|
public static void LogToFile(string msg)
|
||||||
{
|
{
|
||||||
lock (_lock)
|
lock (_lock)
|
||||||
{
|
{
|
||||||
msg = $"{(DateTime.Now - _startTime).TotalSeconds:0.##} - {msg}";
|
File.AppendAllText(LogFile, $"{(DateTime.Now - _startTime).TotalSeconds:0.##} - {msg}\r\n");
|
||||||
|
|
||||||
File.AppendAllText(LogFile, msg + "\r\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,9 +112,11 @@
|
|||||||
<Compile Include="StatusFeed\AStatusMessage.cs" />
|
<Compile Include="StatusFeed\AStatusMessage.cs" />
|
||||||
<Compile Include="StatusFeed\Errors\7zipReturnError.cs" />
|
<Compile Include="StatusFeed\Errors\7zipReturnError.cs" />
|
||||||
<Compile Include="StatusFeed\Errors\FileExtractionError.cs" />
|
<Compile Include="StatusFeed\Errors\FileExtractionError.cs" />
|
||||||
|
<Compile Include="StatusFeed\Errors\GenericException.cs" />
|
||||||
<Compile Include="StatusFeed\Errors\UnconvertedError.cs" />
|
<Compile Include="StatusFeed\Errors\UnconvertedError.cs" />
|
||||||
<Compile Include="StatusFeed\GenericInfo.cs" />
|
<Compile Include="StatusFeed\GenericInfo.cs" />
|
||||||
<Compile Include="StatusFeed\IError.cs" />
|
<Compile Include="StatusFeed\IError.cs" />
|
||||||
|
<Compile Include="StatusFeed\IException.cs" />
|
||||||
<Compile Include="StatusFeed\IInfo.cs" />
|
<Compile Include="StatusFeed\IInfo.cs" />
|
||||||
<Compile Include="StatusFeed\IStatusMessage.cs" />
|
<Compile Include="StatusFeed\IStatusMessage.cs" />
|
||||||
<Compile Include="StatusFeed\IUserIntervention.cs" />
|
<Compile Include="StatusFeed\IUserIntervention.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user