Skip to content

Commit

Permalink
Add exception handling for exception logging (#229)
Browse files Browse the repository at this point in the history
* Add exception handling for exception logging

* Add System.Runtime.Serialization.Primitives package
  • Loading branch information
Arkatufus authored Jun 30, 2021
1 parent b351032 commit 26f84af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Hyperion/Hyperion.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.3.0" />
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.6' ">
<DefineConstants>$(DefineConstants);NETSTANDARD16</DefineConstants>
</PropertyGroup>
Expand Down
14 changes: 13 additions & 1 deletion src/Hyperion/ValueSerializers/ObjectSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading;
using Hyperion.Extensions;

Expand Down Expand Up @@ -103,7 +104,18 @@ public override void WriteManifest(Stream stream, SerializerSession session)
public override void WriteValue(Stream stream, object value, SerializerSession session)
=> _writer(stream, value, session);

public override object ReadValue(Stream stream, DeserializerSession session) => _reader(stream, session);
public override object ReadValue(Stream stream, DeserializerSession session)
{
try
{
return _reader(stream, session);
}
catch (Exception e)
{
throw new SerializationException(
$"Failed to deserialize object of type [{Type}] from the stream. Cause: {e.Message}", e);
}
}

public override Type GetElementType() => Type;

Expand Down

0 comments on commit 26f84af

Please sign in to comment.