Skip to main content

plexor_core/erasure/
error.rs

1// Copyright 2025 Alecks Gates
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7//! Error types for the erasure module.
8
9use std::any::TypeId;
10use thiserror::Error;
11
12/// Errors that can occur when working with type-erased wrappers
13#[derive(Error, Debug)]
14pub enum ErasureError {
15    /// Type mismatch when trying to convert a type-erased neuron to a specific type
16    #[error(
17        "Neuron type mismatch: expected payload type {expected_payload_type:?} and codec type {expected_codec_type:?}, but found payload type {actual_payload_type:?} and codec type {actual_codec_type:?}"
18    )]
19    NeuronTypeMismatch {
20        expected_payload_type: TypeId,
21        expected_codec_type: TypeId,
22        actual_payload_type: TypeId,
23        actual_codec_type: TypeId,
24    },
25
26    /// Type mismatch when trying to convert a type-erased payload to a specific type
27    #[error(
28        "Payload type mismatch: expected payload type {expected_payload_type:?} and codec type {expected_codec_type:?}, but found payload type {actual_payload_type:?} and codec type {actual_codec_type:?}"
29    )]
30    PayloadTypeMismatch {
31        expected_payload_type: TypeId,
32        expected_codec_type: TypeId,
33        actual_payload_type: TypeId,
34        actual_codec_type: TypeId,
35    },
36
37    /// Type mismatch when trying to convert a type-erased synapse to a specific type
38    #[error(
39        "Synapse type mismatch: expected payload type {expected_payload_type:?} and codec type {expected_codec_type:?}, but found payload type {actual_payload_type:?} and codec type {actual_codec_type:?}"
40    )]
41    SynapseTypeMismatch {
42        expected_payload_type: TypeId,
43        expected_codec_type: TypeId,
44        actual_payload_type: TypeId,
45        actual_codec_type: TypeId,
46    },
47}
48
49/// Result type for erasure operations
50pub type ErasureResult<T> = Result<T, ErasureError>;