Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exception handling for exception logging #229

Merged
merged 3 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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