From 74c11a5bf883c3d3dcd3dc2013c8a8f0449a0774 Mon Sep 17 00:00:00 2001 From: Ambr0se Date: Wed, 3 Dec 2025 22:38:39 +0800 Subject: [PATCH 1/2] fix: Visual empty lines in exception output --- managed/src/SwiftlyS2.Core/Bootstrap.cs | 1 + .../src/SwiftlyS2.Core/Misc/SwiftlyLogger.cs | 3 + managed/src/TestPlugin/TestPlugin.cs | 112 ++++++++++++++++++ 3 files changed, 116 insertions(+) diff --git a/managed/src/SwiftlyS2.Core/Bootstrap.cs b/managed/src/SwiftlyS2.Core/Bootstrap.cs index 5f8e6e262..3cc2e4a5e 100644 --- a/managed/src/SwiftlyS2.Core/Bootstrap.cs +++ b/managed/src/SwiftlyS2.Core/Bootstrap.cs @@ -40,6 +40,7 @@ private static IntPtr SteamAPIDLLResolver( string libraryName, Assembly assembly public static void Start( IntPtr nativeTable, int nativeTableSize, string basePath, string logPath ) { Environment.SetEnvironmentVariable("SWIFTLY_MANAGED_ROOT", basePath); + Environment.SetEnvironmentVariable("SWIFTLY_MANAGED_LOG", logPath); NativeBinding.BindNatives(nativeTable, nativeTableSize); NativeLibrary.SetDllImportResolver(typeof(NativeMethods).Assembly, SteamAPIDLLResolver); diff --git a/managed/src/SwiftlyS2.Core/Misc/SwiftlyLogger.cs b/managed/src/SwiftlyS2.Core/Misc/SwiftlyLogger.cs index 8dfb45bb9..5e5b98b6b 100644 --- a/managed/src/SwiftlyS2.Core/Misc/SwiftlyLogger.cs +++ b/managed/src/SwiftlyS2.Core/Misc/SwiftlyLogger.cs @@ -52,7 +52,10 @@ public void Log( LogLevel logLevel, EventId eventId, TState state, Excep if (exception != null) { FileLogger.LogException(exception, exception.Message); + // Temporarily use a reasonable width for exception output to avoid visual empty lines + AnsiConsole.Profile.Width = 200; AnsiConsole.WriteException(exception); + AnsiConsole.Profile.Width = 13337; } AnsiConsole.Reset(); diff --git a/managed/src/TestPlugin/TestPlugin.cs b/managed/src/TestPlugin/TestPlugin.cs index 2e86f7677..339324a33 100644 --- a/managed/src/TestPlugin/TestPlugin.cs +++ b/managed/src/TestPlugin/TestPlugin.cs @@ -14,6 +14,7 @@ using SwiftlyS2.Shared.SchemaDefinitions; using SwiftlyS2.Shared.ProtobufDefinitions; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using SwiftlyS2.Shared.Events; using SwiftlyS2.Shared.Memory; @@ -1136,6 +1137,117 @@ public void LineOfSightCommand( ICommandContext context ) .ForEach(targetPlayer => context.Reply($"Line of sight to {targetPlayer.Controller!.PlayerName}: {player.PlayerPawn!.HasLineOfSight(targetPlayer.PlayerPawn!)}")); } + [Command("ex")] + public void ExceptionCommand( ICommandContext context ) + { + throw new Exception(); + } + + [Command("ex1")] + public void DeepExceptionCommand( ICommandContext _ ) + { + [MethodImpl(MethodImplOptions.NoInlining)] + void ThrowLevel1() + { + ThrowLevel2(); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + void ThrowLevel2() + { + ThrowLevel3(); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + void ThrowLevel3() + { + ThrowLevel4(); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + void ThrowLevel4() + { + ThrowLevel5(); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + void ThrowLevel5() + { + ThrowLevel6(); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + void ThrowLevel6() + { + ThrowLevel7(); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + void ThrowLevel7() + { + ThrowLevel8(); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + void ThrowLevel8() + { + ThrowLevel9(); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + void ThrowLevel9() + { + ThrowLevel10(); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + void ThrowLevel10() + { + try + { + ThrowInnerLevel1(); + } + catch (Exception ex) + { + throw new Exception("Deep nested exception from level 10", ex); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + void ThrowInnerLevel1() + { + try + { + ThrowInnerLevel2(); + } + catch (Exception ex) + { + throw new InvalidOperationException("Inner exception level 1", ex); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + void ThrowInnerLevel2() + { + try + { + ThrowInnerLevel3(); + } + catch (Exception ex) + { + throw new ArgumentException("Inner exception level 2", ex); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + void ThrowInnerLevel3() + { + throw new NullReferenceException("Root cause exception"); + } + + ThrowLevel1(); + } + public override void Unload() { Console.WriteLine("TestPlugin unloaded"); From 65fd1854c8f8f46e38d5b986be5883c19cdfe03b Mon Sep 17 00:00:00 2001 From: Ambr0se Date: Wed, 3 Dec 2025 22:42:10 +0800 Subject: [PATCH 2/2] chore: Clean up code --- managed/src/TestPlugin/TestPlugin.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/managed/src/TestPlugin/TestPlugin.cs b/managed/src/TestPlugin/TestPlugin.cs index 339324a33..94d544a59 100644 --- a/managed/src/TestPlugin/TestPlugin.cs +++ b/managed/src/TestPlugin/TestPlugin.cs @@ -1137,12 +1137,6 @@ public void LineOfSightCommand( ICommandContext context ) .ForEach(targetPlayer => context.Reply($"Line of sight to {targetPlayer.Controller!.PlayerName}: {player.PlayerPawn!.HasLineOfSight(targetPlayer.PlayerPawn!)}")); } - [Command("ex")] - public void ExceptionCommand( ICommandContext context ) - { - throw new Exception(); - } - [Command("ex1")] public void DeepExceptionCommand( ICommandContext _ ) {