• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tari-project / tari / 16123384529

07 Jul 2025 05:11PM UTC coverage: 64.327% (-7.6%) from 71.89%
16123384529

push

github

web-flow
chore: new release v4.9.0-pre.0 (#7289)

Description
---
new release esmeralda

77151 of 119935 relevant lines covered (64.33%)

227108.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.33
/comms/core/src/peer_manager/error.rs
1
// Copyright 2019 The Tari Project
2
//
3
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
4
// following conditions are met:
5
//
6
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
7
// disclaimer.
8
//
9
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
10
// following disclaimer in the documentation and/or other materials provided with the distribution.
11
//
12
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
13
// products derived from this software without specific prior written permission.
14
//
15
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
16
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
21
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
22

23
// use std::sync::PoisonError;
24

25
use std::fmt;
26

27
use multiaddr::Multiaddr;
28
use tari_common_sqlite::error::StorageError;
29
use tari_utilities::hex::{Hex, HexError};
30
use thiserror::Error;
31
use tokio::task::JoinError;
32

33
use crate::peer_manager::NodeId;
34

35
/// Error type for [PeerManager](super::PeerManager).
36
#[derive(Debug, Error, Clone)]
37
pub enum PeerManagerError {
38
    #[error("The requested peer does not exist: {0}")]
39
    PeerNotFound(DisplayVec),
40
    #[error("DB Data inconsistency: {0}")]
41
    DataInconsistency(String),
42
    #[error("The peer has been banned")]
43
    BannedPeer,
44
    #[error("A problem has been encountered with the sql database: {0}")]
45
    StorageError(String),
46
    #[error("An error occurred while migrating the database: {0}")]
47
    MigrationError(String),
48
    #[error("Identity signature is invalid")]
49
    InvalidIdentitySignature,
50
    #[error("Identity signature missing")]
51
    MissingIdentitySignature,
52
    #[error("Invalid peer address: {0}")]
53
    MultiaddrError(String),
54
    #[error("Unable to parse any of the network addresses offered by the connecting peer")]
55
    PeerIdentityNoValidAddresses,
56
    #[error("Invalid peer feature bits '{bits:#x}'")]
57
    InvalidPeerFeatures { bits: u32 },
58
    #[error("Address {address} not found for peer {node_id}")]
59
    AddressNotFoundError { address: Multiaddr, node_id: NodeId },
60
    #[error("Protocol error: {0}")]
61
    ProtocolError(String),
62
    #[error("Invalid version string")]
63
    InvalidVersionString,
64
    #[error("Peer version {peer_version} to older than the minimum required version {min_version}")]
65
    PeerVersionTooOld { min_version: String, peer_version: String },
66
    #[error("Hex conversion error: `{0}`")]
67
    HexError(String),
68
    #[error("Tokio task join error: `{0}`")]
69
    JoinError(String),
70
    #[error("Process error: `{0}`")]
71
    ProcessError(String),
72
}
73
impl From<JoinError> for PeerManagerError {
74
    fn from(err: JoinError) -> Self {
×
75
        PeerManagerError::JoinError(err.to_string())
×
76
    }
×
77
}
78

79
impl From<StorageError> for PeerManagerError {
80
    fn from(err: StorageError) -> Self {
×
81
        PeerManagerError::StorageError(err.to_string())
×
82
    }
×
83
}
84

85
impl From<HexError> for PeerManagerError {
86
    fn from(value: HexError) -> Self {
×
87
        PeerManagerError::HexError(value.to_string())
×
88
    }
×
89
}
90

91
impl From<std::io::Error> for PeerManagerError {
92
    fn from(value: std::io::Error) -> Self {
×
93
        PeerManagerError::StorageError(value.to_string())
×
94
    }
×
95
}
96

97
/// Display helper struct for a vector of strings.
98
#[derive(Debug, Error, Clone)]
99
pub struct DisplayVec(Vec<NodeId>);
100

101
impl fmt::Display for DisplayVec {
102
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2✔
103
        write!(
2✔
104
            f,
2✔
105
            "[{}]",
2✔
106
            self.0.iter().map(|v| v.to_hex()).collect::<Vec<_>>().join(", ")
4✔
107
        )
2✔
108
    }
2✔
109
}
110

111
impl PeerManagerError {
112
    pub fn peer_not_found(peer: &NodeId) -> Self {
218✔
113
        PeerManagerError::PeerNotFound(DisplayVec(vec![peer.clone()]))
218✔
114
    }
218✔
115

116
    pub fn peers_not_found<T>(peers: T) -> Self
1✔
117
    where T: AsRef<[NodeId]> {
1✔
118
        PeerManagerError::PeerNotFound(DisplayVec(peers.as_ref().to_vec()))
1✔
119
    }
1✔
120
}
121

122
#[cfg(test)]
123
mod tests {
124
    use super::*;
125

126
    #[test]
127
    fn test_peer_not_found() {
1✔
128
        let peers = [
1✔
129
            NodeId::from_hex("abb1556d806c2ff042f433ca0a").unwrap(),
1✔
130
            NodeId::from_hex("ba9ab662a6d974c5a607562326").unwrap(),
1✔
131
            NodeId::from_hex("97676095b1901327bdc36e8cb6").unwrap(),
1✔
132
        ];
1✔
133

1✔
134
        let error = PeerManagerError::peers_not_found(&peers);
1✔
135
        assert_eq!(
1✔
136
            error.to_string(),
1✔
137
            "The requested peer does not exist: [abb1556d806c2ff042f433ca0a, ba9ab662a6d974c5a607562326, \
1✔
138
             97676095b1901327bdc36e8cb6]"
1✔
139
        );
1✔
140

141
        let error = PeerManagerError::peer_not_found(&peers[0]);
1✔
142
        assert_eq!(
1✔
143
            error.to_string(),
1✔
144
            "The requested peer does not exist: [abb1556d806c2ff042f433ca0a]"
1✔
145
        );
1✔
146
    }
1✔
147
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc