Skip to content

Commit

Permalink
Handle non-utf8 output from builds
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Jul 30, 2023
1 parent 8af474a commit 87d9e79
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 21 deletions.
7 changes: 3 additions & 4 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ impl Client {
Ok(())
}

pub async fn download_raw(&self, krate: &Crate) -> Result<String> {
pub async fn download_raw(&self, krate: &Crate) -> Result<Vec<u8>> {
retry(|| self._download_raw(krate)).await
}

async fn _download_raw(&self, krate: &Crate) -> Result<String> {
async fn _download_raw(&self, krate: &Crate) -> Result<Vec<u8>> {
let response = self
.inner
.get_object()
Expand All @@ -63,8 +63,7 @@ impl Client {
.send()
.await?;
let bytes = response.body.collect().await?;
let blob = bytes.to_vec();
Ok(String::from_utf8(blob).unwrap())
Ok(bytes.to_vec())
}

pub async fn upload_html(&self, krate: &Crate, data: Vec<u8>) -> Result<()> {
Expand Down
5 changes: 3 additions & 2 deletions src/diagnose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use regex::Regex;
static ANSI_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new("\x1b(\\[[0-9;?]*[A-HJKSTfhilmnsu]|\\(B)").unwrap());

pub fn diagnose(krate: &mut Crate, output: &str) -> Result<()> {
let output = ANSI_REGEX.replace_all(output, "").to_string();
pub fn diagnose(krate: &mut Crate, output: &[u8]) -> Result<()> {
let output = String::from_utf8_lossy(output);
let output = ANSI_REGEX.replace_all(&output, "").to_string();
// Strip ANSI escape codes from the output;
krate.status = if output.contains("Undefined Behavior: ") {
Status::UB {
Expand Down
5 changes: 3 additions & 2 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ function scroll_to_ub() {{
}
}

pub fn render_crate(krate: &Crate, output: &str) -> String {
pub fn render_crate(krate: &Crate, output: &[u8]) -> String {
let output = String::from_utf8_lossy(output);
let (css, mut encoded) =
ansi_to_html::convert_escaped(format!("{}/{}", krate.name, krate.version), output);
ansi_to_html::convert_escaped(format!("{}/{}", krate.name, krate.version), &output);

// Remove blank rows from the bottom of the terminal output
let ending = "\n</span>";
Expand Down
13 changes: 5 additions & 8 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub async fn run(args: Args) -> Result<()> {
let args = args.clone();
let client = client.clone();

let test_end_delimiter_with_dashes = format!("-{}-", *TEST_END_DELIMITER);
let test_end_delimiter_with_dashes = format!("-{}-\n", *TEST_END_DELIMITER).into_bytes();

let mut child = spawn_worker(&args, cpu);

Expand All @@ -138,10 +138,10 @@ pub async fn run(args: Args) -> Result<()> {
.await
.unwrap();

let mut output = String::new();
let mut output = Vec::new();
loop {
let bytes_read = stdout.read_line(&mut output).await.unwrap();
if output.trim_end().ends_with(&test_end_delimiter_with_dashes) {
let bytes_read = stdout.read_until(b'\n', &mut output).await.unwrap();
if output.ends_with(&test_end_delimiter_with_dashes) {
output.truncate(output.len() - test_end_delimiter_with_dashes.len() - 1);
break;
}
Expand All @@ -155,10 +155,7 @@ pub async fn run(args: Args) -> Result<()> {
let rendered = render::render_crate(&krate, &output);

// Upload both
client
.upload_raw(&krate, output.clone().into_bytes())
.await
.unwrap();
client.upload_raw(&krate, output).await.unwrap();
client
.upload_html(&krate, rendered.into_bytes())
.await
Expand Down
6 changes: 1 addition & 5 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ async fn sync_all_html(client: Arc<Client>) -> Result<Vec<Crate>> {
header.set_size(raw.len() as u64);
header.set_mode(0o644);
header.set_cksum();
all_raw
.lock()
.await
.append(&header, raw.as_bytes())
.unwrap();
all_raw.lock().await.append(&header, &*raw).unwrap();
}

let rendered = render::render_crate(&krate, &raw);
Expand Down

0 comments on commit 87d9e79

Please sign in to comment.