summaryrefslogtreecommitdiffstats
path: root/src/endpoint/error.rs
blob: dc4468abc2fcfe05eb819e6f68257a69c1187105 (plain)
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
use thiserror::Error as ThisError;

use crate::util::docker::ContainerHash;

#[derive(ThisError, Debug)]
pub enum ContainerError {

    #[error("Error during container run: {container_id}")]
    ContainerError {
        container_id: ContainerHash,
        uri: String,
    },

    #[error("{0}")]
    Err(anyhow::Error),
}

impl ContainerError {
    pub fn container_error(container_id: ContainerHash, uri: String) -> Self {
        ContainerError::ContainerError { container_id, uri }
    }

    pub fn explain_container_error(&self) -> Option<String> {
        match self {
            ContainerError::ContainerError { container_id, uri } => Some({
                indoc::formatdoc!(r#"
                    Container did not exit successfully: {container_id}
                    It was not stopped because of this.

                    Use

                        docker --host {uri} exec -it {container_id} /bin/bash

                    to access and debug.
                    "#, uri = uri, container_id = container_id)
            }),
            _ => None,
        }
    }
}

impl From<anyhow::Error> for ContainerError {
    fn from(ae: anyhow::Error) -> Self {
        ContainerError::Err(ae)
    }
}