Skip to main content

ostrya_server/
error.rs

1//! The error type of the server.
2
3use std::io;
4use std::net::SocketAddr;
5
6/// The result type of the crate.
7pub type Result<T> = std::result::Result<T, Error>;
8
9/// The error of [`bind`](crate::bind) and of
10/// [`ReceiveEndpoint::new`](crate::ReceiveEndpoint::new).
11///
12/// Each error occurs before the server or the host accepts a connection. An
13/// error on one connection ends that connection and no other.
14#[derive(Debug, thiserror::Error)]
15#[non_exhaustive]
16pub enum Error {
17    /// A listen address that cannot be bound, or whose local address cannot
18    /// be read.
19    #[error("bind {addr}: {source}")]
20    Bind {
21        /// The listen address from the options.
22        addr: SocketAddr,
23        /// The I/O error of the bind or of the read of the local address.
24        #[source]
25        source: io::Error,
26    },
27    /// TLS files that give no server configuration.
28    #[error("server tls: {0}")]
29    Tls(String),
30    /// Options that the server refuses. The text states the reason.
31    #[error("invalid serve options: {0}")]
32    Options(String),
33    /// A malformed line of the push credential file.
34    ///
35    /// The error names the line by its number and holds no byte of it.
36    #[error("push credentials: line {line}: {message}")]
37    Credentials {
38        /// The number of the line, from 1.
39        line: usize,
40        /// The defect of the line.
41        message: String,
42    },
43    /// An error of the repository.
44    #[error(transparent)]
45    Repo(#[from] ostrya::Error),
46    /// An I/O error.
47    #[error(transparent)]
48    Io(#[from] io::Error),
49}