Commit 6c2f9dac authored by Ian Jackson's avatar Ian Jackson
Browse files

channel errors: Include what we were doing

parent 5b54d3e0
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -82,13 +82,20 @@ impl<R: Runtime> ChanBuilder<R> {
                .record_attempt();
        }

        let map_ioe = |ioe: io::Error| Error::Io {
        let map_ioe = |action: &'static str| {
            move |ioe: io::Error| Error::Io {
                action,
                peer: *addr,
                source: ioe.into(),
            }
        };

        // Establish a TCP connection.
        let stream = self.runtime.connect(addr).await.map_err(map_ioe)?;
        let stream = self
            .runtime
            .connect(addr)
            .await
            .map_err(map_ioe("connect"))?;

        {
            self.event_sender
@@ -102,11 +109,11 @@ impl<R: Runtime> ChanBuilder<R> {
            .tls_connector
            .negotiate_unvalidated(stream, "ignored")
            .await
            .map_err(map_ioe)?;
            .map_err(map_ioe("TLS negotiation"))?;

        let peer_cert = tls
            .peer_certificate()
            .map_err(map_ioe)?
            .map_err(map_ioe("TLS certs"))?
            .ok_or(Error::Internal("TLS connection with no peer certificate"))?;

        {
+3 −5
Original line number Diff line number Diff line
@@ -29,15 +29,13 @@ pub enum Error {
    Proto(#[from] tor_proto::Error),

    /// Network IO error or TLS error
    #[error("Network IO error, or TLS error, talking to {peer}")]
    #[error("Network IO error, or TLS error, in {action}, talking to {peer}")]
    Io {
        /// Who we were talking to
        peer: SocketAddr,

        // TODO
        // /// What we were doing
        // action: &'static str,
        // as per https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/262#note_2772820
        /// What we were doing
        action: &'static str,

        /// What happened.  Might be some TLS library error wrapped up in io::Error
        #[source]