swiftide_docker_executor/
errors.rs1use std::{convert::Infallible, path::StripPrefixError};
2
3use thiserror::Error;
4
5#[derive(Error, Debug)]
6pub enum DockerExecutorError {
7 #[error("error from docker: {0}")]
8 Docker(#[from] bollard::errors::Error),
9
10 #[error(transparent)]
11 Context(#[from] ContextError),
12
13 #[error("container state missing for: {0}")]
14 ContainerStateMissing(String),
15
16 #[error(transparent)]
17 Init(#[from] ClientError),
18
19 #[error("error with io {0}")]
20 Io(#[from] std::io::Error),
21
22 #[error(transparent)]
23 Transform(#[from] MangleError),
24
25 #[error("error starting container: {0}")]
26 Start(anyhow::Error),
27
28 #[error(transparent)]
29 ImageBuild(#[from] ImageBuildError),
30
31 #[error(transparent)]
32 DockerfilePreparation(#[from] DockerfileError),
33
34 #[error(transparent)]
35 ContainerStart(#[from] ContainerStartError),
36}
37
38#[derive(Error, Debug)]
39pub enum ContextError {
40 #[error("error while trying to ignore files: {0}")]
41 FailedIgnore(#[from] ignore::Error),
42
43 #[error("failed while walking files in context: {0}")]
44 Walk(#[from] walkdir::Error),
45
46 #[error(transparent)]
47 Io(#[from] std::io::Error),
48
49 #[error("failed to convert to relative path{0}")]
50 RelativePath(#[from] StripPrefixError),
51
52 #[error("error with custom dockerfile: {0}")]
53 CustomDockerfile(String),
54}
55
56#[derive(Error, Debug)]
57pub enum ClientError {
58 #[error("failed to connect to docker: {0}")]
59 Init(bollard::errors::Error),
60}
61
62#[derive(Error, Debug)]
63pub enum MangleError {
64 #[error("Failed to read Dockerfile: {0}")]
65 DockerfileReadError(std::io::Error), #[error("invalid dockerfile")]
68 InvalidDockerfile, }
71
72#[derive(Error, Debug)]
73pub enum ImageBuildError {
74 #[error("error compressing context: {0}")]
75 Compression(std::io::Error),
76
77 #[error("build failed: {0}")]
78 BuildFailed(String),
79
80 #[error("build error: {0}")]
81 BuildError(String),
82
83 #[error("invalid image name: {0}")]
84 InvalidImageName(String),
85}
86
87#[derive(Error, Debug)]
88pub enum DockerfileError {
89 #[error("Failed to mangle dockerfile: {0}")]
90 MangleError(#[from] MangleError),
91
92 #[error("Failed to write temporary file: {0}")]
93 TempFileError(#[from] std::io::Error),
94
95 #[error("Invalid dockerfile path: {0}")]
96 InvalidPath(String),
97}
98
99#[derive(Error, Debug)]
100pub enum ContainerStartError {
101 #[error("Failed to create container: {0}")]
102 Creation(bollard::errors::Error),
103
104 #[error("Failed to start container: {0}")]
105 Start(bollard::errors::Error),
106
107 #[error("Failed to get container port: {0}")]
108 PortMapping(String),
109
110 #[error("Error from logs: {0}")]
111 Logs(String),
112}
113impl From<Infallible> for DockerExecutorError {
114 fn from(_: Infallible) -> Self {
115 unreachable!()
116 }
117}
118
119impl From<Infallible> for ContextError {
120 fn from(_: Infallible) -> Self {
121 unreachable!()
122 }
123}