Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion flare/src/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3395,13 +3395,50 @@ fn resolve_revision(
Ok(info)
}

#[derive(Debug)]
struct RevisionLookupError {
repository: String,
revision: String,
source: Box<dyn std::error::Error>,
}

impl std::fmt::Display for RevisionLookupError {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
formatter,
"cannot resolve {}@{}: {}",
self.repository, self.revision, self.source
)
}
}

impl std::error::Error for RevisionLookupError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(self.source.as_ref())
}
}

fn resolve_primary_target(
api: &Api,
repo: &Repo,
requested: Option<&str>,
progress: Option<&flare_helios::core::progress::AcquisitionProgress>,
) -> Result<(Repo, String)> {
let info = resolve_revision(api, repo, progress)?;
let info = resolve_revision(api, repo, progress).map_err(|source| {
if matches!(
source.downcast_ref::<ApiError>(),
Some(ApiError::RequestError(error))
if matches!(error.as_ref(), ureq::Error::StatusCode(404))
) {
Box::new(RevisionLookupError {
repository: repo.url(),
revision: repo.revision().to_owned(),
source,
})
} else {
source
}
})?;
let filename = choose_file(
info.siblings.into_iter().map(|file| file.rfilename),
requested,
Expand Down Expand Up @@ -8580,6 +8617,9 @@ pub(crate) mod tests {
.to_string();
worker.join().unwrap();
assert!(error.contains(&status.to_string()), "{error}");
if status == 404 {
assert!(error.contains(&format!("owner/model@{revision}")), "{error}");
}
assert_eq!(log.lock().unwrap().documents[&route], 1);
}
}
Expand Down