From dc0b57444c25b36bb9aaf6ebcfbc26f86e379ed3 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 7 Jun 2024 11:10:38 +0800 Subject: [PATCH] optimize the code to apply Hecate suggestion --- .../ApplicationLogs/Store/LogStorageStore.cs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs b/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs index 105da2c786..4371f36e9b 100644 --- a/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs +++ b/src/Plugins/ApplicationLogs/Store/LogStorageStore.cs @@ -160,20 +160,13 @@ public Guid PutStackItemState(StackItem stackItem) { _snapshot.Put(key, BinarySerializer.Serialize(stackItem, ExecutionEngineLimits.Default with { MaxItemSize = (uint)Settings.Default.MaxStackSize })); } - catch (NotSupportedException ex) // Ref. https://github.com/neo-project/neo/issues/3296 - { - var message = ex.Message.Length > 1024 ? string.Concat(ex.Message.AsSpan(0, 1021), "...") : ex.Message; - _snapshot.Put(key, Encoding.UTF8.GetBytes("Not Supported Exception: " + message)); - } - catch (FormatException ex) - { - var message = ex.Message.Length > 1024 ? string.Concat(ex.Message.AsSpan(0, 1021), "...") : ex.Message; - _snapshot.Put(key, Encoding.UTF8.GetBytes("Format Exception: " + message)); - } catch (Exception ex) { - var message = ex.Message.Length > 1024 ? string.Concat(ex.Message.AsSpan(0, 1021), "...") : ex.Message; - _snapshot.Put(key, Encoding.UTF8.GetBytes("Exception: " + message)); + var detailedException = ex.Message; + if (detailedException.Length > 1024) + detailedException = string.Concat(detailedException.AsSpan(0, 1021), "..."); + ByteString exceptionRecord = new(Encoding.UTF8.GetBytes(detailedException)); + _snapshot.Put(key, BinarySerializer.Serialize(exceptionRecord, ExecutionEngineLimits.Default with { MaxItemSize = (uint)Settings.Default.MaxStackSize })); } return id; }