From d9b60d97b8293c18a0d8b9516fdb2dd9f8740b2e Mon Sep 17 00:00:00 2001 From: Maximilien Noal Date: Fri, 5 Jul 2024 12:22:50 +0200 Subject: [PATCH] fix: stacktraces (removed Ben.Demistify package) (#766) Signed-off-by: Maximilien Noal --- src/Spice86.Core/CLI/CommandLineParser.cs | 11 ------- .../Function/Dump/ExecutionFlowDumper.cs | 1 - .../Gdb/GdbCommandBreakPointHandler.cs | 8 ++--- .../Emulator/Gdb/GdbCommandMemoryHandler.cs | 2 -- .../Emulator/Gdb/GdbCommandRegisterHandler.cs | 2 -- .../Emulator/Gdb/GdbCustomCommandsHandler.cs | 1 - src/Spice86.Core/Emulator/Gdb/GdbServer.cs | 3 -- .../OperatingSystem/DosFileManager.cs | 8 ----- src/Spice86.Core/Emulator/ProgramExecutor.cs | 2 -- src/Spice86.Core/Emulator/VM/EmulationLoop.cs | 2 -- src/Spice86.Core/Emulator/VM/PauseHandler.cs | 6 ++-- src/Spice86.Core/Spice86.Core.csproj | 1 - src/Spice86/Spice86.csproj | 1 - src/Spice86/ViewModels/MainWindowViewModel.cs | 30 ++++++++----------- .../ViewModelBaseWithErrorDialog.cs | 3 -- 15 files changed, 16 insertions(+), 65 deletions(-) diff --git a/src/Spice86.Core/CLI/CommandLineParser.cs b/src/Spice86.Core/CLI/CommandLineParser.cs index a91044ba9..e2cd07853 100644 --- a/src/Spice86.Core/CLI/CommandLineParser.cs +++ b/src/Spice86.Core/CLI/CommandLineParser.cs @@ -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; @@ -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); } } diff --git a/src/Spice86.Core/Emulator/Function/Dump/ExecutionFlowDumper.cs b/src/Spice86.Core/Emulator/Function/Dump/ExecutionFlowDumper.cs index 5b31c795a..07f567032 100644 --- a/src/Spice86.Core/Emulator/Function/Dump/ExecutionFlowDumper.cs +++ b/src/Spice86.Core/Emulator/Function/Dump/ExecutionFlowDumper.cs @@ -51,7 +51,6 @@ public ExecutionFlowRecorder ReadFromFileOrCreate(string filePath) { try { return JsonSerializer.Deserialize(File.ReadAllText(filePath)) ?? new(); } catch (JsonException e) { - e.Demystify(); throw new UnrecoverableException($"File {filePath} is not valid", e); } } diff --git a/src/Spice86.Core/Emulator/Gdb/GdbCommandBreakPointHandler.cs b/src/Spice86.Core/Emulator/Gdb/GdbCommandBreakPointHandler.cs index fcf1669ff..b0643cb82 100644 --- a/src/Spice86.Core/Emulator/Gdb/GdbCommandBreakPointHandler.cs +++ b/src/Spice86.Core/Emulator/Gdb/GdbCommandBreakPointHandler.cs @@ -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; - /// /// Handles GDB commands related to breakpoints and stepping through instructions. /// @@ -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"); } @@ -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); } diff --git a/src/Spice86.Core/Emulator/Gdb/GdbCommandMemoryHandler.cs b/src/Spice86.Core/Emulator/Gdb/GdbCommandMemoryHandler.cs index 317f2319c..c6f0f4d99 100644 --- a/src/Spice86.Core/Emulator/Gdb/GdbCommandMemoryHandler.cs +++ b/src/Spice86.Core/Emulator/Gdb/GdbCommandMemoryHandler.cs @@ -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); } @@ -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); } diff --git a/src/Spice86.Core/Emulator/Gdb/GdbCommandRegisterHandler.cs b/src/Spice86.Core/Emulator/Gdb/GdbCommandRegisterHandler.cs index 667e729f8..d0b9ee7fb 100644 --- a/src/Spice86.Core/Emulator/Gdb/GdbCommandRegisterHandler.cs +++ b/src/Spice86.Core/Emulator/Gdb/GdbCommandRegisterHandler.cs @@ -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); } @@ -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); } diff --git a/src/Spice86.Core/Emulator/Gdb/GdbCustomCommandsHandler.cs b/src/Spice86.Core/Emulator/Gdb/GdbCustomCommandsHandler.cs index 0c6e07fc8..5d0cefa85 100644 --- a/src/Spice86.Core/Emulator/Gdb/GdbCustomCommandsHandler.cs +++ b/src/Spice86.Core/Emulator/Gdb/GdbCustomCommandsHandler.cs @@ -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); } } diff --git a/src/Spice86.Core/Emulator/Gdb/GdbServer.cs b/src/Spice86.Core/Emulator/Gdb/GdbServer.cs index 4d00a2200..8c1baca22 100644 --- a/src/Spice86.Core/Emulator/Gdb/GdbServer.cs +++ b/src/Spice86.Core/Emulator/Gdb/GdbServer.cs @@ -6,7 +6,6 @@ using Spice86.Core.Emulator.Memory; using Spice86.Core.Emulator.VM; using Spice86.Shared.Interfaces; -using System.Diagnostics; /// /// A GDB server that allows for remote debugging of the emulator. @@ -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 { @@ -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; diff --git a/src/Spice86.Core/Emulator/OperatingSystem/DosFileManager.cs b/src/Spice86.Core/Emulator/OperatingSystem/DosFileManager.cs index be0e80857..91d1d60dd 100644 --- a/src/Spice86.Core/Emulator/OperatingSystem/DosFileManager.cs +++ b/src/Spice86.Core/Emulator/OperatingSystem/DosFileManager.cs @@ -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; @@ -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); } @@ -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); } @@ -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); } @@ -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"); } @@ -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); } @@ -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); } @@ -514,7 +507,6 @@ public DosFileOperationResult WriteFileUsingHandle(ushort fileHandle, ushort wri Span data = _memory.GetSpan((int)bufferAddress, writeLength); file.RandomAccessFile.Write(data); } catch (IOException e) { - e.Demystify(); throw new UnrecoverableException("IOException while writing file", e); } diff --git a/src/Spice86.Core/Emulator/ProgramExecutor.cs b/src/Spice86.Core/Emulator/ProgramExecutor.cs index f56861e32..8c0c92c61 100644 --- a/src/Spice86.Core/Emulator/ProgramExecutor.cs +++ b/src/Spice86.Core/Emulator/ProgramExecutor.cs @@ -19,7 +19,6 @@ using Spice86.Shared.Interfaces; using Spice86.Shared.Utils; -using System.Diagnostics; using System.Security.Cryptography; /// @@ -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); } } diff --git a/src/Spice86.Core/Emulator/VM/EmulationLoop.cs b/src/Spice86.Core/Emulator/VM/EmulationLoop.cs index 67e7274b4..85018b48d 100644 --- a/src/Spice86.Core/Emulator/VM/EmulationLoop.cs +++ b/src/Spice86.Core/Emulator/VM/EmulationLoop.cs @@ -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(); diff --git a/src/Spice86.Core/Emulator/VM/PauseHandler.cs b/src/Spice86.Core/Emulator/VM/PauseHandler.cs index c87634179..e95a7ae67 100644 --- a/src/Spice86.Core/Emulator/VM/PauseHandler.cs +++ b/src/Spice86.Core/Emulator/VM/PauseHandler.cs @@ -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; + /// /// Provides functionality to handle pausing of the emulator. /// @@ -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); } diff --git a/src/Spice86.Core/Spice86.Core.csproj b/src/Spice86.Core/Spice86.Core.csproj index 398e94ecd..3f1196ead 100644 --- a/src/Spice86.Core/Spice86.Core.csproj +++ b/src/Spice86.Core/Spice86.Core.csproj @@ -48,7 +48,6 @@ - diff --git a/src/Spice86/Spice86.csproj b/src/Spice86/Spice86.csproj index 5b1741c4a..10fe8eb01 100644 --- a/src/Spice86/Spice86.csproj +++ b/src/Spice86/Spice86.csproj @@ -62,7 +62,6 @@ - all diff --git a/src/Spice86/ViewModels/MainWindowViewModel.cs b/src/Spice86/ViewModels/MainWindowViewModel.cs index 1cdf3162a..e055a95eb 100644 --- a/src/Spice86/ViewModels/MainWindowViewModel.cs +++ b/src/Spice86/ViewModels/MainWindowViewModel.cs @@ -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; /// @@ -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"); } diff --git a/src/Spice86/ViewModels/ViewModelBaseWithErrorDialog.cs b/src/Spice86/ViewModels/ViewModelBaseWithErrorDialog.cs index 9169e9898..a63669691 100644 --- a/src/Spice86/ViewModels/ViewModelBaseWithErrorDialog.cs +++ b/src/Spice86/ViewModels/ViewModelBaseWithErrorDialog.cs @@ -6,8 +6,6 @@ using Spice86.Infrastructure; using Spice86.Models.Debugging; -using System.Diagnostics; - public partial class ViewModelBaseWithErrorDialog : ViewModelBase { protected readonly ITextClipboard _textClipboard; @@ -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)));