summaryrefslogtreecommitdiffstats
path: root/src/endpoint/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/endpoint/error.rs')
-rw-r--r--src/endpoint/error.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/endpoint/error.rs b/src/endpoint/error.rs
new file mode 100644
index 0000000..a6a6d7b
--- /dev/null
+++ b/src/endpoint/error.rs
@@ -0,0 +1,45 @@
+use thiserror::Error as ThisError;
+
+use crate::util::docker::ContainerHash;
+use crate::package::Script;
+
+#[derive(ThisError, Debug)]
+pub enum ContainerError {
+
+ #[error("Error during container run: {container_id}")]
+ ContainerError {
+ container_id: ContainerHash,
+ },
+
+ #[error("{0}")]
+ Err(anyhow::Error),
+}
+
+impl ContainerError {
+ pub fn container_error(container_id: ContainerHash) -> Self {
+ ContainerError::ContainerError { container_id }
+ }
+
+ pub fn explain_container_error(&self) -> Option<String> {
+ match self {
+ ContainerError::ContainerError { container_id } => Some({
+ indoc::formatdoc!(r#"
+ Container did not exit successfully: {container_id}
+ Use
+
+ docker exec -it {container_id} /bin/bash
+
+ to access and debug.
+ "#, container_id = container_id)
+ }),
+ _ => None,
+ }
+ }
+}
+
+impl From<anyhow::Error> for ContainerError {
+ fn from(ae: anyhow::Error) -> Self {
+ ContainerError::Err(ae)
+ }
+}
+