Skip to content

Commit

Permalink
fix: stacktraces (removed Ben.Demistify package) (#766)
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilien Noal <[email protected]>
  • Loading branch information
maximilien-noal authored Jul 5, 2024
1 parent de6ca78 commit d9b60d9
Show file tree
Hide file tree
Showing 15 changed files with 16 additions and 65 deletions.
11 changes: 0 additions & 11 deletions src/Spice86.Core/CLI/CommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

using CommandLine;

using Serilog;
using Serilog.Events;

using Spice86.Core.Emulator.Errors;
using Spice86.Core.Emulator.Function;
using Spice86.Logging;
using Spice86.Shared.Emulator.Errors;
using Spice86.Shared.Utils;

Expand Down Expand Up @@ -66,22 +61,16 @@ public static Configuration ParseCommandLine(string[] args) {

return (IOverrideSupplier?)Activator.CreateInstance(supplierClass);
} catch (MethodAccessException exception) {
exception.Demystify();
throw new UnrecoverableException($"Could not load provided class {supplierClassName}", exception);
} catch (TargetInvocationException exception) {
exception.Demystify();
throw new UnrecoverableException($"Could not instantiate provided class {supplierClassName}", exception);
} catch (NotSupportedException exception) {
exception.Demystify();
throw new UnrecoverableException($"Could not instantiate provided class {supplierClassName}", exception);
} catch (ArgumentException exception) {
exception.Demystify();
throw new UnrecoverableException($"Could not instantiate provided class {supplierClassName}", exception);
} catch (MemberAccessException exception) {
exception.Demystify();
throw new UnrecoverableException($"Could not instantiate provided class {supplierClassName}", exception);
} catch (TypeLoadException exception) {
exception.Demystify();
throw new UnrecoverableException($"Could not instantiate provided class {supplierClassName}", exception);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public ExecutionFlowRecorder ReadFromFileOrCreate(string filePath) {
try {
return JsonSerializer.Deserialize<ExecutionFlowRecorder>(File.ReadAllText(filePath)) ?? new();
} catch (JsonException e) {
e.Demystify();
throw new UnrecoverableException($"File {filePath} is not valid", e);
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/Spice86.Core/Emulator/Gdb/GdbCommandBreakPointHandler.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
namespace Spice86.Core.Emulator.Gdb;

using System.Diagnostics;
using Serilog.Events;

using Spice86.Core.Emulator.VM;
using Spice86.Core.Emulator.Memory;
using Spice86.Core.Emulator.VM;
using Spice86.Core.Emulator.VM.Breakpoint;
using Spice86.Shared.Interfaces;
using Spice86.Shared.Utils;

using Serilog.Events;

/// <summary>
/// Handles GDB commands related to breakpoints and stepping through instructions.
/// </summary>
Expand Down Expand Up @@ -84,7 +82,6 @@ public void OnBreakPointReached(BreakPoint breakPoint) {
try {
_gdbIo.SendResponse(_gdbIo.GenerateResponse("S05"));
} catch (IOException e) {
e.Demystify();
if (_loggerService.IsEnabled(LogEventLevel.Error)) {
_loggerService.Error(e, "IOException while sending breakpoint info");
}
Expand Down Expand Up @@ -123,7 +120,6 @@ public void OnBreakPointReached(BreakPoint breakPoint) {
}
return new AddressBreakPoint((BreakPointType)breakPointType, address, OnBreakPointReached, false);
} catch (FormatException nfe) {
nfe.Demystify();
if (_loggerService.IsEnabled(LogEventLevel.Error)) {
_loggerService.Error(nfe, "Cannot parse breakpoint {Command}", command);
}
Expand Down
2 changes: 0 additions & 2 deletions src/Spice86.Core/Emulator/Gdb/GdbCommandMemoryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public string ReadMemory(string commandContent) {

return _gdbIo.GenerateResponse(response.ToString());
} catch (FormatException nfe) {
nfe.Demystify();
if (_loggerService.IsEnabled(Serilog.Events.LogEventLevel.Error)) {
_loggerService.Error(nfe, "Memory read requested but could not understand the request {CommandContent}", commandContent);
}
Expand Down Expand Up @@ -119,7 +118,6 @@ public string WriteMemory(string commandContent) {
_memory.LoadData(address, data);
return _gdbIo.GenerateResponse("OK");
} catch (FormatException nfe) {
nfe.Demystify();
if (_loggerService.IsEnabled(Serilog.Events.LogEventLevel.Error)) {
_loggerService.Error(nfe, "Memory write requested but could not understand the request {CommandContent}", commandContent);
}
Expand Down
2 changes: 0 additions & 2 deletions src/Spice86.Core/Emulator/Gdb/GdbCommandRegisterHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public string ReadRegister(string commandContent) {
}
return _gdbIo.GenerateResponse(_gdbFormatter.FormatValueAsHex32(GetRegisterValue((int)index)));
} catch (FormatException nfe) {
nfe.Demystify();
if (_loggerService.IsEnabled(Serilog.Events.LogEventLevel.Error)) {
_loggerService.Error(nfe, "Register read requested but could not understand the request {CommandContent}", commandContent);
}
Expand All @@ -82,7 +81,6 @@ public string WriteAllRegisters(string commandContent) {

return _gdbIo.GenerateResponse("OK");
} catch (FormatException nfe) {
nfe.Demystify();
if (_loggerService.IsEnabled(Serilog.Events.LogEventLevel.Error)) {
_loggerService.Error(nfe, "Register write requested but could not understand the request {CommandContent}", commandContent);
}
Expand Down
1 change: 0 additions & 1 deletion src/Spice86.Core/Emulator/Gdb/GdbCustomCommandsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ private string DumpAll(ExecutionFlowRecorder executionFlowRecorder, FunctionHand
_recordedDataWriter.DumpAll(executionFlowRecorder, functionHandler);
return _gdbIo.GenerateMessageToDisplayResponse($"Dumped everything in {_recordedDataWriter.DumpDirectory}");
} catch (IOException e) {
e.Demystify();
return _gdbIo.GenerateMessageToDisplayResponse(e.Message);
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/Spice86.Core/Emulator/Gdb/GdbServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Spice86.Core.Emulator.Memory;
using Spice86.Core.Emulator.VM;
using Spice86.Shared.Interfaces;
using System.Diagnostics;

/// <summary>
/// A GDB server that allows for remote debugging of the emulator.
Expand Down Expand Up @@ -140,7 +139,6 @@ private void RunServer() {
AcceptOneConnection(gdbIo);
_gdbIo = null;
} catch (IOException e) {
e.Demystify();
if (_isRunning) {
_loggerService.Error(e, "Error in the GDB server, restarting it...");
} else {
Expand All @@ -149,7 +147,6 @@ private void RunServer() {
}
}
} catch (Exception e) {
e.Demystify();
_loggerService.Error(e, "Unhandled error in the GDB server, restarting it");
} finally {
_state.IsRunning = false;
Expand Down
8 changes: 0 additions & 8 deletions src/Spice86.Core/Emulator/OperatingSystem/DosFileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace Spice86.Core.Emulator.OperatingSystem;
using Spice86.Shared.Interfaces;
using Spice86.Shared.Utils;

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

Expand Down Expand Up @@ -85,7 +84,6 @@ public DosFileOperationResult CloseFile(ushort fileHandle) {
file.RandomAccessFile.Close();
}
} catch (IOException e) {
e.Demystify();
throw new UnrecoverableException("IOException while closing file", e);
}

Expand Down Expand Up @@ -114,7 +112,6 @@ public DosFileOperationResult CreateFileUsingHandle(string fileName, ushort file
testFileStream = File.Create(prefixedPath);
File.SetAttributes(prefixedPath, (FileAttributes)fileAttribute);
} catch (IOException e) {
e.Demystify();
if (_loggerService.IsEnabled(LogEventLevel.Warning)) {
_loggerService.Warning(e, "Error while creating a file using a handle with {FileName} and {FileAttribute}", fileName, fileAttribute);
}
Expand Down Expand Up @@ -199,7 +196,6 @@ public DosFileOperationResult FindFirstMatchingFile(string fileSpec, ushort sear
return DosFileOperationResult.NoValue();

} catch (IOException e) {
e.Demystify();
if (_loggerService.IsEnabled(LogEventLevel.Error)) {
_loggerService.Error(e, "Error while walking path {SearchFolder} or getting attributes", searchFolder);
}
Expand Down Expand Up @@ -324,7 +320,6 @@ private bool TryUpdateDosTransferAreaWithFileMatch(DosDiskTransferArea dta, stri
UpdateDosTransferAreaWithFileMatch(dta, filename, searchAttributes);
}
catch (IOException e) {
e.Demystify();
if (_loggerService.IsEnabled(LogEventLevel.Warning)){
_loggerService.Warning(e, "Error while getting attributes");
}
Expand Down Expand Up @@ -370,7 +365,6 @@ public DosFileOperationResult MoveFilePointerUsingHandle(byte originOfMove, usho
uint newOffset = Seek(randomAccessFile, originOfMove, offset);
return DosFileOperationResult.Value32(newOffset);
} catch (IOException e) {
e.Demystify();
if (_loggerService.IsEnabled(LogEventLevel.Error)) {
_loggerService.Error(e, "An error occurred while seeking file {Error}", e);
}
Expand Down Expand Up @@ -453,7 +447,6 @@ public DosFileOperationResult ReadFile(ushort fileHandle, ushort readLength, uin
try {
actualReadLength = file.RandomAccessFile.Read(buffer, 0, readLength);
} catch (IOException e) {
e.Demystify();
throw new UnrecoverableException("IOException while reading file", e);
}

Expand Down Expand Up @@ -514,7 +507,6 @@ public DosFileOperationResult WriteFileUsingHandle(ushort fileHandle, ushort wri
Span<byte> data = _memory.GetSpan((int)bufferAddress, writeLength);
file.RandomAccessFile.Write(data);
} catch (IOException e) {
e.Demystify();
throw new UnrecoverableException("IOException while writing file", e);
}

Expand Down
2 changes: 0 additions & 2 deletions src/Spice86.Core/Emulator/ProgramExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
using Spice86.Shared.Interfaces;
using Spice86.Shared.Utils;

using System.Diagnostics;
using System.Security.Cryptography;

/// <inheritdoc cref="IProgramExecutor"/>
Expand Down Expand Up @@ -228,7 +227,6 @@ private void LoadFileToRun(Configuration configuration, ExecutableFileLoader loa
byte[] fileContent = loader.LoadFile(executableFileName, configuration.ExeArgs);
CheckSha256Checksum(fileContent, configuration.ExpectedChecksumValue);
} catch (IOException e) {
e.Demystify();
throw new UnrecoverableException($"Failed to read file {executableFileName}", e);
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/Spice86.Core/Emulator/VM/EmulationLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ public void Run() {
// Actually a signal generated code requested Exit
return;
} catch (InvalidVMOperationException e) {
e.Demystify();
throw;
} catch (Exception e) {
e.Demystify();
throw new InvalidVMOperationException(_cpuState, e);
}
_machineBreakpoints.OnMachineStop();
Expand Down
6 changes: 2 additions & 4 deletions src/Spice86.Core/Emulator/VM/PauseHandler.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
namespace Spice86.Core.Emulator.VM;

using System.Diagnostics;
using System.Threading;

using Spice86.Shared.Emulator.Errors;
using Spice86.Shared.Interfaces;

using System.Threading;

/// <summary>
/// Provides functionality to handle pausing of the emulator.
/// </summary>
Expand Down Expand Up @@ -77,7 +76,6 @@ private void Await() {
_manualResetEvent.WaitOne(Timeout.Infinite);
}
} catch (AbandonedMutexException exception) {
exception.Demystify();
Thread.CurrentThread.Interrupt();
throw new UnrecoverableException($"Fatal error while waiting paused in {nameof(Await)}", exception);
}
Expand Down
1 change: 0 additions & 1 deletion src/Spice86.Core/Spice86.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Ben.Demystifier" Version="0.4.1" />
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.2.2" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
Expand Down
1 change: 0 additions & 1 deletion src/Spice86/Spice86.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
<PackageReference Include="Semi.Avalonia.DataGrid" Version="11.0.7.2" />
<PackageReference Include="Semi.Avalonia.TreeDataGrid" Version="11.0.1" />
<PackageReference Include="bodong.Avalonia.PropertyGrid" Version="11.0.10.1" />
<PackageReference Include="Ben.Demystifier" Version="0.4.1" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="ErrorProne.NET.CoreAnalyzers" Version="0.1.2">
<PrivateAssets>all</PrivateAssets>
Expand Down
30 changes: 12 additions & 18 deletions src/Spice86/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,35 @@
namespace Spice86.ViewModels;

using System.Threading;
using System.Diagnostics;

using Avalonia;

using Serilog.Events;

using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using Avalonia.Platform.Storage;
using Avalonia.Threading;

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

using Serilog.Events;

using Spice86.Core.CLI;
using Spice86.Core.Emulator;
using Spice86.Shared.Emulator.Keyboard;
using Spice86.Shared.Emulator.Mouse;
using Spice86.Shared.Interfaces;

using Key = Spice86.Shared.Emulator.Keyboard.Key;
using MouseButton = Spice86.Shared.Emulator.Mouse.MouseButton;
using Avalonia.Media.Imaging;
using Avalonia.Platform;

using Spice86.Core.Emulator.Devices.Sound;
using Spice86.Core.Emulator.InternalDebugger;

using Spice86.Infrastructure;
using Spice86.Interfaces;
using Spice86.Shared.Diagnostics;
using Spice86.Infrastructure;
using Spice86.Shared.Emulator.Keyboard;
using Spice86.Shared.Emulator.Mouse;
using Spice86.Shared.Emulator.Video;
using Spice86.Shared.Interfaces;

using System.Threading;

using Key = Spice86.Shared.Emulator.Keyboard.Key;
using MouseButton = Spice86.Shared.Emulator.Mouse.MouseButton;
using Timer = System.Timers.Timer;

/// <inheritdoc cref="Spice86.Shared.Interfaces.IGui" />
Expand Down Expand Up @@ -497,7 +492,6 @@ private void MachineThread() {
try {
StartProgramExecutor();
} catch (Exception e) {
e.Demystify();
if (_loggerService.IsEnabled(LogEventLevel.Error)) {
_loggerService.Error(e, "An error occurred during execution");
}
Expand Down
3 changes: 0 additions & 3 deletions src/Spice86/ViewModels/ViewModelBaseWithErrorDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using Spice86.Infrastructure;
using Spice86.Models.Debugging;

using System.Diagnostics;

public partial class ViewModelBaseWithErrorDialog : ViewModelBase {
protected readonly ITextClipboard _textClipboard;

Expand All @@ -29,7 +27,6 @@ protected void ShowError(Exception e) {
[RelayCommand]
public async Task CopyExceptionToClipboard() {
if(Exception is not null) {
Exception.Demystify();
await _textClipboard.SetTextAsync(
Newtonsoft.Json.JsonConvert.SerializeObject(
new ExceptionInfo(Exception.TargetSite?.ToString(), Exception.Message, Exception.StackTrace)));
Expand Down

0 comments on commit d9b60d9

Please sign in to comment.