Skip to content

Commit 417eae1

Browse files
authored
fix: Visual empty lines in exception output (#151)
1 parent d459b72 commit 417eae1

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

managed/src/SwiftlyS2.Core/Bootstrap.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ private static IntPtr SteamAPIDLLResolver( string libraryName, Assembly assembly
4040
public static void Start( IntPtr nativeTable, int nativeTableSize, string basePath, string logPath )
4141
{
4242
Environment.SetEnvironmentVariable("SWIFTLY_MANAGED_ROOT", basePath);
43+
Environment.SetEnvironmentVariable("SWIFTLY_MANAGED_LOG", logPath);
4344
NativeBinding.BindNatives(nativeTable, nativeTableSize);
4445
NativeLibrary.SetDllImportResolver(typeof(NativeMethods).Assembly, SteamAPIDLLResolver);
4546

managed/src/SwiftlyS2.Core/Misc/SwiftlyLogger.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ public void Log<TState>( LogLevel logLevel, EventId eventId, TState state, Excep
5252
if (exception != null)
5353
{
5454
FileLogger.LogException(exception, exception.Message);
55+
// Temporarily use a reasonable width for exception output to avoid visual empty lines
56+
AnsiConsole.Profile.Width = 200;
5557
AnsiConsole.WriteException(exception);
58+
AnsiConsole.Profile.Width = 13337;
5659
}
5760

5861
AnsiConsole.Reset();

managed/src/TestPlugin/TestPlugin.cs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using SwiftlyS2.Shared.SchemaDefinitions;
1515
using SwiftlyS2.Shared.ProtobufDefinitions;
1616
using System.Diagnostics.CodeAnalysis;
17+
using System.Runtime.CompilerServices;
1718
using System.Runtime.InteropServices;
1819
using SwiftlyS2.Shared.Events;
1920
using SwiftlyS2.Shared.Memory;
@@ -1137,6 +1138,111 @@ public void LineOfSightCommand( ICommandContext context )
11371138
.ForEach(targetPlayer => context.Reply($"Line of sight to {targetPlayer.Controller!.PlayerName}: {player.PlayerPawn!.HasLineOfSight(targetPlayer.PlayerPawn!)}"));
11381139
}
11391140

1141+
[Command("ex1")]
1142+
public void DeepExceptionCommand( ICommandContext _ )
1143+
{
1144+
[MethodImpl(MethodImplOptions.NoInlining)]
1145+
void ThrowLevel1()
1146+
{
1147+
ThrowLevel2();
1148+
}
1149+
1150+
[MethodImpl(MethodImplOptions.NoInlining)]
1151+
void ThrowLevel2()
1152+
{
1153+
ThrowLevel3();
1154+
}
1155+
1156+
[MethodImpl(MethodImplOptions.NoInlining)]
1157+
void ThrowLevel3()
1158+
{
1159+
ThrowLevel4();
1160+
}
1161+
1162+
[MethodImpl(MethodImplOptions.NoInlining)]
1163+
void ThrowLevel4()
1164+
{
1165+
ThrowLevel5();
1166+
}
1167+
1168+
[MethodImpl(MethodImplOptions.NoInlining)]
1169+
void ThrowLevel5()
1170+
{
1171+
ThrowLevel6();
1172+
}
1173+
1174+
[MethodImpl(MethodImplOptions.NoInlining)]
1175+
void ThrowLevel6()
1176+
{
1177+
ThrowLevel7();
1178+
}
1179+
1180+
[MethodImpl(MethodImplOptions.NoInlining)]
1181+
void ThrowLevel7()
1182+
{
1183+
ThrowLevel8();
1184+
}
1185+
1186+
[MethodImpl(MethodImplOptions.NoInlining)]
1187+
void ThrowLevel8()
1188+
{
1189+
ThrowLevel9();
1190+
}
1191+
1192+
[MethodImpl(MethodImplOptions.NoInlining)]
1193+
void ThrowLevel9()
1194+
{
1195+
ThrowLevel10();
1196+
}
1197+
1198+
[MethodImpl(MethodImplOptions.NoInlining)]
1199+
void ThrowLevel10()
1200+
{
1201+
try
1202+
{
1203+
ThrowInnerLevel1();
1204+
}
1205+
catch (Exception ex)
1206+
{
1207+
throw new Exception("Deep nested exception from level 10", ex);
1208+
}
1209+
}
1210+
1211+
[MethodImpl(MethodImplOptions.NoInlining)]
1212+
void ThrowInnerLevel1()
1213+
{
1214+
try
1215+
{
1216+
ThrowInnerLevel2();
1217+
}
1218+
catch (Exception ex)
1219+
{
1220+
throw new InvalidOperationException("Inner exception level 1", ex);
1221+
}
1222+
}
1223+
1224+
[MethodImpl(MethodImplOptions.NoInlining)]
1225+
void ThrowInnerLevel2()
1226+
{
1227+
try
1228+
{
1229+
ThrowInnerLevel3();
1230+
}
1231+
catch (Exception ex)
1232+
{
1233+
throw new ArgumentException("Inner exception level 2", ex);
1234+
}
1235+
}
1236+
1237+
[MethodImpl(MethodImplOptions.NoInlining)]
1238+
void ThrowInnerLevel3()
1239+
{
1240+
throw new NullReferenceException("Root cause exception");
1241+
}
1242+
1243+
ThrowLevel1();
1244+
}
1245+
11401246
public override void Unload()
11411247
{
11421248
Console.WriteLine("TestPlugin unloaded");

0 commit comments

Comments
 (0)