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 bollard: {0}")]
8 Docker(#[from] bollard::errors::Error),
9
10 #[error("error building context for image: {0}")]
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("error transforming dockerfile: {0}")]
23 Transform(#[from] MangleError),
24
25 #[error("error starting container: {0}")]
26 Start(anyhow::Error),
27
28 #[error("Failed to build image: {0}")]
29 ImageBuild(#[from] ImageBuildError),
30
31 #[error("Failed to prepare dockerfile: {0}")]
32 DockerfilePreparation(#[from] DockerfileError),
33
34 #[error("Failed to start container: {0}")]
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
53#[derive(Error, Debug)]
54pub enum ClientError {
55 #[error("failed to connect to docker: {0}")]
56 Init(bollard::errors::Error),
57}
58
59#[derive(Error, Debug)]
60pub enum MangleError {
61 #[error("Failed to read Dockerfile: {0}")]
62 DockerfileReadError(std::io::Error), #[error("invalid dockerfile")]
65 InvalidDockerfile, }
68
69#[derive(Error, Debug)]
70pub enum ImageBuildError {
71 #[error("error compressing context: {0}")]
72 Compression(std::io::Error),
73
74 #[error("build failed: {0}")]
75 BuildFailed(String),
76
77 #[error("build error: {0}")]
78 BuildError(String),
79
80 #[error("invalid image name: {0}")]
81 InvalidImageName(String),
82}
83
84#[derive(Error, Debug)]
85pub enum DockerfileError {
86 #[error("Failed to mangle dockerfile: {0}")]
87 MangleError(#[from] MangleError),
88
89 #[error("Failed to write temporary file: {0}")]
90 TempFileError(#[from] std::io::Error),
91
92 #[error("Invalid dockerfile path: {0}")]
93 InvalidPath(String),
94}
95
96#[derive(Error, Debug)]
97pub enum ContainerStartError {
98 #[error("Failed to create container: {0}")]
99 Creation(bollard::errors::Error),
100
101 #[error("Failed to start container: {0}")]
102 Start(bollard::errors::Error),
103
104 #[error("Failed to get container port: {0}")]
105 PortMapping(String),
106
107 #[error("Error from logs: {0}")]
108 Logs(String),
109}
110impl From<Infallible> for DockerExecutorError {
111 fn from(_: Infallible) -> Self {
112 unreachable!()
113 }
114}
115
116impl From<Infallible> for ContextError {
117 fn from(_: Infallible) -> Self {
118 unreachable!()
119 }
120}