Skip to content

Commit

Permalink
server: handle non-utf8 characters from actions
Browse files Browse the repository at this point in the history
  • Loading branch information
pnmadelaine committed Sep 26, 2023
1 parent a93172d commit 4f52844
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions typhon/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ use tokio::io::{AsyncReadExt, AsyncWriteExt};
pub enum Error {
InvalidKey,
InvalidSecrets,
NonUtf8,
ScriptNotFound,
SecretsNotFound,
WrongRecipient,
}

impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
use Error::*;
match self {
Error::InvalidKey => write!(f, "Invalid key"),
Error::InvalidSecrets => write!(f, "Wrong secrets format"),
Error::ScriptNotFound => write!(f, "Action script not found"),
Error::SecretsNotFound => write!(f, "Secrets file not found"),
Error::WrongRecipient => write!(f, "Secrets file uncrypted with wrong key"),
InvalidKey => write!(f, "Invalid key"),
InvalidSecrets => write!(f, "Wrong secrets format"),
NonUtf8 => write!(f, "Action outputted non-UTF8 characters"),
ScriptNotFound => write!(f, "Action script not found"),
SecretsNotFound => write!(f, "Secrets file not found"),
WrongRecipient => write!(f, "Secrets file uncrypted with wrong key"),
}
}
}
Expand Down Expand Up @@ -95,9 +98,15 @@ pub async fn run(
drop(stdin); // send EOF

let mut res = String::new();
stdout.read_to_string(&mut res).await.unwrap();
stdout
.read_to_string(&mut res)
.await
.map_err(|_| Error::NonUtf8)?;
let mut log = String::new();
stderr.read_to_string(&mut log).await.unwrap();
stderr
.read_to_string(&mut log)
.await
.map_err(|_| Error::NonUtf8)?;

Ok((res, log))
}
Expand Down

0 comments on commit 4f52844

Please sign in to comment.