nimble_host_logic/
err.rs

1/*
2 * Copyright (c) Peter Bjorklund. All rights reserved. https://github.com/nimble-rust/nimble
3 * Licensed under the MIT License. See LICENSE in the project root for license information.
4 */
5
6use crate::combinator::CombinatorError;
7use crate::combine::HostCombinatorError;
8use crate::HostConnectionId;
9use err_rs::{ErrorLevel, ErrorLevelProvider};
10use freelist_rs::FreeListError;
11use nimble_blob_stream::out_stream::OutStreamError;
12use nimble_participant::ParticipantId;
13use tick_queue::QueueError;
14
15#[derive(Debug)]
16pub enum HostLogicError {
17    UnknownConnectionId(HostConnectionId),
18    FreeListError {
19        connection_id: HostConnectionId,
20        message: FreeListError,
21    },
22    UnknownPartyMember(ParticipantId),
23    NoFreeParticipantIds,
24    BlobStreamErr(OutStreamError),
25    NoDownloadNow,
26    CombinatorError(CombinatorError),
27    HostCombinatorError(HostCombinatorError),
28    NeedConnectRequestFirst,
29    WrongApplicationVersion,
30    QueueError(QueueError),
31}
32
33impl ErrorLevelProvider for HostLogicError {
34    fn error_level(&self) -> ErrorLevel {
35        match self {
36            Self::UnknownConnectionId(_) => ErrorLevel::Warning,
37            Self::FreeListError { .. } => ErrorLevel::Critical,
38            Self::UnknownPartyMember(_) => ErrorLevel::Warning,
39            Self::NoFreeParticipantIds => ErrorLevel::Warning,
40            Self::BlobStreamErr(_) => ErrorLevel::Info,
41            Self::NoDownloadNow => ErrorLevel::Info,
42            Self::CombinatorError(err) => err.error_level(),
43            Self::HostCombinatorError(err) => err.error_level(),
44            Self::NeedConnectRequestFirst => ErrorLevel::Info,
45            Self::WrongApplicationVersion => ErrorLevel::Critical,
46            Self::QueueError(_) => ErrorLevel::Critical,
47        }
48    }
49}
50
51impl From<CombinatorError> for HostLogicError {
52    fn from(err: CombinatorError) -> Self {
53        Self::CombinatorError(err)
54    }
55}
56
57impl From<QueueError> for HostLogicError {
58    fn from(err: QueueError) -> Self {
59        Self::QueueError(err)
60    }
61}
62
63impl From<HostCombinatorError> for HostLogicError {
64    fn from(err: HostCombinatorError) -> Self {
65        Self::HostCombinatorError(err)
66    }
67}
68
69impl From<OutStreamError> for HostLogicError {
70    fn from(err: OutStreamError) -> Self {
71        Self::BlobStreamErr(err)
72    }
73}