From 492d620deac828156f0e672c7059e91d2cdc0e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Wed, 29 Dec 2021 15:15:34 +0100 Subject: [PATCH] feat: add errors for converting packets --- .../Errors/PacketEndNotExpectedError.cs | 19 ++++++++++++++++++ .../Errors/PacketMissingHeaderError.cs | 17 ++++++++++++++++ .../Errors/PacketParameterDeserializeError.cs | 20 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 Core/NosSmooth.Packets/Errors/PacketEndNotExpectedError.cs create mode 100644 Core/NosSmooth.Packets/Errors/PacketMissingHeaderError.cs create mode 100644 Core/NosSmooth.Packets/Errors/PacketParameterDeserializeError.cs diff --git a/Core/NosSmooth.Packets/Errors/PacketEndNotExpectedError.cs b/Core/NosSmooth.Packets/Errors/PacketEndNotExpectedError.cs new file mode 100644 index 0000000..813ab45 --- /dev/null +++ b/Core/NosSmooth.Packets/Errors/PacketEndNotExpectedError.cs @@ -0,0 +1,19 @@ +// +// PacketEndNotExpectedError.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using NosSmooth.Packets.Converters; +using Remora.Results; + +namespace NosSmooth.Packets.Errors; + +/// +/// The end of a packet was not expected. +/// +/// The type converter. +/// The property name. +public record PacketEndNotExpectedError(ITypeConverter Converter, string PropertyName) + : ResultError($"Unexpected packet end reached in {Converter.GetType()} during deserializing the property {PropertyName}"); \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Errors/PacketMissingHeaderError.cs b/Core/NosSmooth.Packets/Errors/PacketMissingHeaderError.cs new file mode 100644 index 0000000..63a0392 --- /dev/null +++ b/Core/NosSmooth.Packets/Errors/PacketMissingHeaderError.cs @@ -0,0 +1,17 @@ +// +// PacketMissingHeaderError.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using NosSmooth.Packets.Packets; +using Remora.Results; + +namespace NosSmooth.Packets.Errors; + +/// +/// Packet is missing header and thus cannot be serialized correctly. +/// +/// The packet that is missing header. +public record PacketMissingHeaderError(IPacket Packet) + : ResultError($"The packet {Packet.GetType().FullName} is missing a header and cannot be serialized."); \ No newline at end of file diff --git a/Core/NosSmooth.Packets/Errors/PacketParameterDeserializeError.cs b/Core/NosSmooth.Packets/Errors/PacketParameterDeserializeError.cs new file mode 100644 index 0000000..68892b5 --- /dev/null +++ b/Core/NosSmooth.Packets/Errors/PacketParameterDeserializeError.cs @@ -0,0 +1,20 @@ +// +// PacketParameterDeserializeError.cs +// +// Copyright (c) František Boháček. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using NosSmooth.Packets.Converters; +using Remora.Results; + +namespace NosSmooth.Packets.Errors; + +/// +/// Could not deserialize one of the packet's properties. +/// +/// The converter that could not deserialize the parameter. +/// The name of the property. +/// The underlying result. +public record PacketParameterDeserializeError(ITypeConverter Converter, string PropertyName, IResult Result) + : ResultError($"There was an error deserializing property {PropertyName} in converter {Converter.GetType().FullName}"); \ No newline at end of file -- 2.48.1