Skip to content

Commit

Permalink
Update errors from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Techassi committed Nov 9, 2023
1 parent 2c907e6 commit afeaf8a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
4 changes: 2 additions & 2 deletions rust/stackable-cockpit/src/common/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub trait SpecIter<S> {
#[derive(Debug, Snafu)]
pub enum ListError {
#[snafu(display("failed to transfer the list file"))]
TransferError { source: FileTransferError },
FileTransfer { source: FileTransferError },
}

/// A [`List`] describes a list of specs. The list can contain any specs, for
Expand Down Expand Up @@ -52,7 +52,7 @@ where
let specs = transfer_client
.get(file, &Yaml::<L>::new())
.await
.context(TransferSnafu)?;
.context(FileTransferSnafu)?;

for (spec_name, spec) in specs.inner() {
map.insert(spec_name.clone(), spec.clone());
Expand Down
6 changes: 3 additions & 3 deletions rust/stackable-cockpit/src/engine/docker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tracing::{debug, instrument};
#[derive(Debug, Snafu)]
pub enum DockerError {
#[snafu(display("failed to read stdout"))]
IoError { source: std::io::Error },
StdoutRead { source: std::io::Error },

#[snafu(display("It seems like Docker is not running on this system"))]
NotRunning,
Expand All @@ -22,10 +22,10 @@ pub async fn check_if_docker_is_running() -> Result<(), DockerError> {
.arg("info")
.stdout(Stdio::null())
.spawn()
.context(IoSnafu)?
.context(StdoutReadSnafu)?
.wait()
.await
.context(IoSnafu)?
.context(StdoutReadSnafu)?
.success()
{
return Ok(());
Expand Down
34 changes: 18 additions & 16 deletions rust/stackable-cockpit/src/engine/kind/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ mod config;
#[derive(Debug, Snafu)]
pub enum KindClusterError {
#[snafu(display("failed to pipe kind config using stdin"))]
IoError { source: std::io::Error },
PipeConfigStdin { source: std::io::Error },

#[snafu(display("failed to obtain stdin handle"))]
StdinError,
ObtainStdinHandle,

#[snafu(display("failed to execute kind command: {error}"))]
CommandError { error: String },
#[snafu(display("failed to execute kind command"))]
CommandError { source: std::io::Error },

#[snafu(display("kind command executed, but returned error: {error}"))]
CommandErroredOut { error: String },

#[snafu(display("missing required binary: {binary}"))]
MissingBinaryError { binary: String },
Expand Down Expand Up @@ -79,25 +82,24 @@ impl KindCluster {
.stderr(Stdio::null())
.stdin(Stdio::piped())
.spawn()
.context(IoSnafu)?;
.context(PipeConfigStdinSnafu)?;

// Pipe in config
let mut stdin = kind_cmd.stdin.take().ok_or(KindClusterError::StdinError)?;
let mut stdin = kind_cmd
.stdin
.take()
.ok_or(KindClusterError::ObtainStdinHandle)?;

stdin
.write_all(config_string.as_bytes())
.await
.context(IoSnafu)?;
.context(PipeConfigStdinSnafu)?;

// Write the piped in data
stdin.flush().await.context(IoSnafu)?;
stdin.flush().await.context(PipeConfigStdinSnafu)?;
drop(stdin);

if let Err(err) = kind_cmd.wait().await {
return Err(KindClusterError::CommandError {
error: err.to_string(),
});
}

kind_cmd.wait().await.context(CommandSnafu)?;
Ok(())
}

Expand Down Expand Up @@ -132,11 +134,11 @@ impl KindCluster {
.args(["get", "clusters"])
.output()
.await
.context(IoSnafu)?;
.context(CommandSnafu)?;

ensure!(
output.status.success(),
CommandSnafu {
CommandErroredOutSnafu {
error: String::from_utf8_lossy(&output.stderr)
}
);
Expand Down
6 changes: 3 additions & 3 deletions rust/stackable-cockpit/src/engine/minikube/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ pub enum MinikubeClusterError {
#[snafu(display(
"failed to determine if a minikube cluster named {cluster_name} already exists"
))]
CheckClusterError {
CheckCluster {
source: std::io::Error,
cluster_name: String,
},

#[snafu(display("missing required binary: {binary}"))]
MissingBinaryError { binary: String },
MissingBinary { binary: String },

#[snafu(display("failed to execute minikube command: {error}"))]
CommandError { error: String },
Expand Down Expand Up @@ -51,7 +51,7 @@ impl MinikubeCluster {

// Check if required binaries are present
if let Some(binary) = binaries_present_with_name(&["docker", "minikube"]) {
return Err(MinikubeClusterError::MissingBinaryError { binary });
return Err(MinikubeClusterError::MissingBinary { binary });
}

// Check if Docker is running
Expand Down

0 comments on commit afeaf8a

Please sign in to comment.