Skip to content

Commit

Permalink
feat: improve error message when repo fetch fails (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
woodruffw authored Jan 19, 2025
1 parent 3c1309c commit 5baaaf2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Nothing to see here (yet!)
* The [excessive-permissions] audit is now more precise about both
reusable workflows and reusable workflow calls (#473)

### Improvements 🌱

* Fetch failures when running `zizmor org/repo` are now more informative (#475)

## v1.2.1

This is a small corrective release for some SARIF behavior that
Expand Down
12 changes: 11 additions & 1 deletion src/github_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use github_actions_models::common::RepositoryUses;
use http_cache_reqwest::{
CACacheManager, Cache, CacheMode, CacheOptions, HttpCache, HttpCacheOptions,
};
use owo_colors::OwoColorize;
use reqwest::{
header::{HeaderMap, ACCEPT, AUTHORIZATION, USER_AGENT},
StatusCode,
Expand Down Expand Up @@ -399,7 +400,16 @@ impl Client {
// TODO: Could probably make this slightly faster by
// streaming asynchronously into the decompression,
// probably with the async-compression crate.
let contents = self.http.get(url).send().await?.bytes().await?;
let resp = self.http.get(&url).send().await?;

if !resp.status().is_success() {
return Err(anyhow!(
"failed to fetch {url}: {status}",
status = resp.status().red()
));
}

let contents = resp.bytes().await?;
let tar = GzDecoder::new(contents.deref());

let mut archive = Archive::new(tar);
Expand Down
13 changes: 11 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,16 @@ fn collect_from_repo_slug(
registry.register_input(workflow.into())?;
}
} else {
let inputs = client.fetch_audit_inputs(&slug)?;
let inputs = client.fetch_audit_inputs(&slug).with_context(|| {
tip(
format!(
"couldn't collect inputs from https://github.com/{owner}/{repo}",
owner = slug.owner,
repo = slug.repo
),
"confirm the repository exists and that you have access to it",
)
})?;

tracing::info!(
"collected {len} inputs from {owner}/{repo}",
Expand All @@ -267,7 +276,7 @@ fn collect_from_repo_slug(
repo = slug.repo
);

for input in client.fetch_audit_inputs(&slug)? {
for input in inputs {
registry.register_input(input)?;
}
}
Expand Down

0 comments on commit 5baaaf2

Please sign in to comment.