nimble_host_logic/
err.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * Copyright (c) Peter Bjorklund. All rights reserved. https://github.com/nimble-rust/nimble
 * Licensed under the MIT License. See LICENSE in the project root for license information.
 */

use crate::combinator::CombinatorError;
use crate::combine::HostCombinatorError;
use crate::HostConnectionId;
use err_rs::{ErrorLevel, ErrorLevelProvider};
use freelist_rs::FreeListError;
use nimble_blob_stream::out_stream::OutStreamError;
use nimble_participant::ParticipantId;
use tick_queue::QueueError;

#[derive(Debug)]
pub enum HostLogicError {
    UnknownConnectionId(HostConnectionId),
    FreeListError {
        connection_id: HostConnectionId,
        message: FreeListError,
    },
    UnknownPartyMember(ParticipantId),
    NoFreeParticipantIds,
    BlobStreamErr(OutStreamError),
    NoDownloadNow,
    CombinatorError(CombinatorError),
    HostCombinatorError(HostCombinatorError),
    NeedConnectRequestFirst,
    WrongApplicationVersion,
    QueueError(QueueError),
}

impl ErrorLevelProvider for HostLogicError {
    fn error_level(&self) -> ErrorLevel {
        match self {
            Self::UnknownConnectionId(_) => ErrorLevel::Warning,
            Self::FreeListError { .. } => ErrorLevel::Critical,
            Self::UnknownPartyMember(_) => ErrorLevel::Warning,
            Self::NoFreeParticipantIds => ErrorLevel::Warning,
            Self::BlobStreamErr(_) => ErrorLevel::Info,
            Self::NoDownloadNow => ErrorLevel::Info,
            Self::CombinatorError(err) => err.error_level(),
            Self::HostCombinatorError(err) => err.error_level(),
            Self::NeedConnectRequestFirst => ErrorLevel::Info,
            Self::WrongApplicationVersion => ErrorLevel::Critical,
            Self::QueueError(_) => ErrorLevel::Critical,
        }
    }
}

impl From<CombinatorError> for HostLogicError {
    fn from(err: CombinatorError) -> Self {
        Self::CombinatorError(err)
    }
}

impl From<QueueError> for HostLogicError {
    fn from(err: QueueError) -> Self {
        Self::QueueError(err)
    }
}

impl From<HostCombinatorError> for HostLogicError {
    fn from(err: HostCombinatorError) -> Self {
        Self::HostCombinatorError(err)
    }
}

impl From<OutStreamError> for HostLogicError {
    fn from(err: OutStreamError) -> Self {
        Self::BlobStreamErr(err)
    }
}