Skip to content

Commit 455e17a

Browse files
Wi1l-B0tajara87
andauthored
Fix: Log stacktrace to get where/why the exception is thrown (#4242)
Co-authored-by: Alvaro <[email protected]>
1 parent 72eab3b commit 455e17a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Neo.Extensions/Utility.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Akka.Actor;
1313
using Akka.Event;
1414
using Neo.Extensions;
15+
using System;
1516
using System.Text;
1617

1718
namespace Neo
@@ -28,7 +29,7 @@ internal class Logger : ReceiveActor
2829
public Logger()
2930
{
3031
Receive<InitializeLogger>(_ => Sender.Tell(new LoggerInitialized()));
31-
Receive<LogEvent>(e => Log(e.LogSource, (LogLevel)e.LogLevel(), e.Message));
32+
Receive<LogEvent>(e => Log(e.LogSource, (LogLevel)e.LogLevel(), $"Akka.LogEvent: {e.Message}{Environment.NewLine}{e.Cause?.StackTrace ?? ""}"));
3233
}
3334
}
3435

src/Neo/Ledger/Blockchain.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ private static void InvokeHandlers(Delegate[] handlers, Action<Delegate> handler
542542
}
543543
catch (Exception ex) when (handler.Target is Plugin plugin)
544544
{
545-
Utility.Log(nameof(plugin), LogLevel.Error, ex);
545+
Utility.Log(nameof(plugin.Name), LogLevel.Error, $"{plugin.Name} exception: {ex.Message}{Environment.NewLine}{ex.StackTrace}");
546546
switch (plugin.ExceptionPolicy)
547547
{
548548
case UnhandledExceptionPolicy.StopNode:
@@ -555,8 +555,7 @@ private static void InvokeHandlers(Delegate[] handlers, Action<Delegate> handler
555555
// Log the exception and continue with the next handler
556556
break;
557557
default:
558-
throw new InvalidCastException(
559-
$"The exception policy {plugin.ExceptionPolicy} is not valid.");
558+
throw new InvalidCastException($"The exception policy {plugin.ExceptionPolicy} is not valid.");
560559
}
561560
}
562561
}

0 commit comments

Comments
 (0)