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
use crate::types::ProtocolPort;
use thiserror::Error;

/// A result type to return `ProcCtlError`s
pub type ProcCtlResult<T> = Result<T, ProcCtlError>;

/// Custom error type for proc-ctl
#[derive(Error, Debug)]
pub enum ProcCtlError {
    /// There was an error communicating with the network
    #[error("network error")]
    NetworkError(#[from] netstat2::error::Error),

    /// The user made an error using the API, a more specific error message will be provided
    #[error("configuration error {0}")]
    ConfigurationError(String),

    /// Fewer ports than expected were found on the matched process
    #[error("too few ports, got {0:?} but expected {1}")]
    TooFewPorts(Vec<ProtocolPort>, usize),

    /// Too few children were found on the matched process
    #[error("too few children, got {0} but expected {1}")]
    TooFewChildren(usize, usize),
}