Subtraction, Simplicity & Conventions review — PR #603 "Report the repository and revision on Hub lookup errors"
Scope reviewed: the single changed file, flare/src/hub.rs (+41/−1), in three parts — new private error type (:3398-3419), the map_err wrapper in resolve_primary_target (:3427-3441), and the strengthened fixture assertion (:8620-8622).
Key findings
- [high] The new
RevisionLookupErrortype (flare/src/hub.rs:3398-3419) and itsApiErrordowncast (:3427-3441) are 22 lines of boilerplate for a message string that no consumer reads as a typed error. The type's only advantage overformat!(...).into()isError::source(), and nothing inflare/orflare-cli/walks the cause chain: the crate alias isBox<dyn std::error::Error>(flare/src/hub.rs:29), the CLI prints Display only (eprintln!("Error: {error}"),flare-cli/src/main.rs:64), and Orbit flattens toStringtwice (flare-cli/src/orbit/controller.rs:2533-2536format!("{node}: {error}"),:2545errors.push(error.to_string())). The change can be a 6-linemap_err, matching the file's dominant idiom. - [medium] The diff is the third inline copy of the "is this a Hub 404" walk over
ApiError/ureq::Error::StatusCode(404)in one file —flare/src/hub.rs:2142,:3383, and the new:3431— while the file already establishes the named-predicate idiom for exactly this (transient_hub_error,flare/src/hub.rs:5460-5472). - [medium] The context lands at the second of two callers of
resolve_revision, duplicating an existing hand-written twin.resolve_primary_targetgets the new wrap (:3427) whilerefresh_model_atalready writes the samerepo@revisioncontext by hand (flare/src/hub.rs:2279-2280). Producing the context insideresolve_revision(:3374-3396) would cover both callers and need no downcast at all, because the 404 arm at:3381still holds a concreteApiError. - [low, conventions] The new operator-visible text has no documentation delta.
docs/cli-design.md:920-929specifies the-tp1404 retry and records behavior but says nothing about the message;AGENTS.md:52-58treats error text as specification and routes unresolved defects todocs/TODO.txt, which is precisely the path #489's reviewer (original-el8, CHANGES_REQUESTED 2026-11-28) chose and this PR bypasses without adding the entry. - What is already fine: no dead code, no flags/config knobs, no new dependencies, no added fallback branches, no public surface change (the struct is private), and the test change (
:8620-8622) is minimal and proportional. The subtraction problem is localized to suggestion 1.
Suggestion 1 [high] — Delete RevisionLookupError; the Error::source() it exists for is never read
flare/src/hub.rs:3398-3419, verbatim (new code):
#[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())
}
}
and its only construction site, flare/src/hub.rs:3427-3441:
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
}
})?;
Evidence that source() is unread:
- Crate error alias:
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;(flare/src/hub.rs:29). - Terminal printer formats Display only:
eprintln!("Error: {error}");(flare-cli/src/main.rs:64). - Orbit flattens to a
String:format!("{node}: {error}").into()(flare-cli/src/orbit/controller.rs:2533-2536) anderrors.push(error.to_string())(:2545). - No
.chain()orError::sourcewalk exists anywhere inflare/orflare-cli/; the onlyimpl std::error::Errortypes inflare/srcarePublisherKeyRequired(:47),HttpError(flare/src/http_client.rs:69(not opened)) and this new one (:3415), and every downcast in the crate is forPublisherKeyRequired(flare/src/hub.rs:6965,:7038) — an error typeresolve_revisioncannot produce.
Concrete replacement — remove the struct and both impl blocks entirely (:3398-3419) and write the wrapper as a one-line format!, deleting the nested matches! guard's boxing branch:
let info = resolve_revision(api, repo, progress).map_err(|error| {
if matches!(
error.downcast_ref::<ApiError>(),
Some(ApiError::RequestError(error))
if matches!(error.as_ref(), ureq::Error::StatusCode(404))
) {
format!("cannot resolve {}@{}: {error}", repo.url(), repo.revision()).into()
} else {
error
}
})?;
Box<dyn Error>: From<String>, and {error} still embeds the original ApiError, so the PR's stated guarantee ("the message retains HTTP 404 without assigning a cause", PR body) is preserved verbatim. Saves ~22 lines plus two hand-written trait impls.
This is the module's dominant pattern, not a taste preference:
flare/src/hub.rs:2280:.map_err(|error| format!("cannot check {}@{revision} for updates: {error}; the local version is unchanged (use --offline to skip the check)", origin.repository))?;:2658:.map_err(|error| format!("core file is unavailable: {name}: {error}"))?;:3297:.map_err(|error| format!("cannot read token file {}: {error}", path.display()))?;:3057:result.map_err(|error| error.to_string().into())
AGENTS.md:188-190 ("Reject unsupported abstractions and churn… Do not add frameworks, extension points, speculative compatibility, fallback layers, or configuration switches without a concrete requirement") is the convention this trip: a private typed error whose source() no code reads is a speculative extension point where a formatted string is what the callers actually consume.
Suggestion 2 [medium] — Name the Hub-404 predicate instead of adding a third inline copy
The same match now appears three times in one file. Instance A (pre-existing), flare/src/hub.rs:2141-2146:
let body = match get(revision) {
Err(ureq::Error::StatusCode(404)) if tp1_revision_alias(revision) => {
get(&format!("{revision}-tp1"))?
}
result => result?,
};
Instance B (pre-existing), flare/src/hub.rs:3381-3384:
let info = match with_transient_retry(|| api.repo(repo.clone()).info()) {
Err(ApiError::RequestError(error))
if matches!(error.as_ref(), ureq::Error::StatusCode(404))
&& tp1_revision_alias(revision) =>
Instance C (added by this PR), flare/src/hub.rs:3428-3432:
if matches!(
source.downcast_ref::<ApiError>(),
Some(ApiError::RequestError(error))
if matches!(error.as_ref(), ureq::Error::StatusCode(404))
) {
The repo already establishes the named-predicate idiom over ApiError for this exact purpose, flare/src/hub.rs:5457-5472:
/// Errors from Hub resolution or file identity that may succeed when retried.
/// Authentication, missing repositories, missing files, and malformed responses
/// are permanent and are never retried, so the signed binding is unchanged.
fn transient_hub_error(error: &ApiError) -> bool {
let ApiError::RequestError(request) = error else {
return false;
};
match request.as_ref() {
ureq::Error::Timeout(_)
| ureq::Error::Io(_)
| ureq::Error::HostNotFound
| ureq::Error::ConnectionFailed => true,
ureq::Error::StatusCode(status) => matches!(status, 408 | 429 | 500..=599),
_ => false,
}
}
Concrete simplification — add one sibling predicate next to transient_hub_error (:5472) and use it at all three sites:
/// Whether a Hub revision request failed because the reference does not exist.
fn hub_not_found(error: &ApiError) -> bool {
matches!(error, ApiError::RequestError(request) if matches!(request.as_ref(), ureq::Error::StatusCode(404)))
}
Then B becomes Err(error) if hub_not_found(&error) && tp1_revision_alias(revision) => and C becomes if error.downcast_ref::<ApiError>().is_some_and(hub_not_found). This removes the nested matches! guard at :3428-3432 and — the maintainability point — keeps the retry decision (:3383) and the diagnostic decision (:3431) from drifting apart, since they must stay pinned to the same status to remain truthful about what was retried.
Suggestion 3 [medium] — Put the context where the concrete ApiError still exists; the wrap site duplicates an existing message
The same repo@revision context now exists twice in one file for two callers of one function.
New wrapper, flare/src/hub.rs:3427-3441 (quoted in suggestion 1), applies only to resolve_primary_target (:3421), reached from acquisition and from the test-only fetch_primary_with_progress (:3480).
The other caller already writes it by hand, flare/src/hub.rs:2279-2280:
let info = resolve_revision(&api, &repo, None)
.map_err(|error| format!("cannot check {}@{revision} for updates: {error}; the local version is unchanged (use --offline to skip the check)", origin.repository))?;
If the context were produced inside resolve_revision (flare/src/hub.rs:3374-3396), both callers would get it and the entire downcast_ref::<ApiError> guard at :3428-3432 would disappear, because at the retry match on :3381 the error is still a concrete ApiError:
let info = match with_transient_retry(|| api.repo(repo.clone()).info()) {
Err(ApiError::RequestError(error))
if matches!(error.as_ref(), ureq::Error::StatusCode(404))
&& tp1_revision_alias(revision) =>
{
check_cancel(progress)?;
let alias = format!("{revision}-tp1");
log::info!("Hugging Face revision {revision} returned 404, trying {alias}");
let repo = Repo::with_revision(repo.url(), RepoType::Model, alias);
with_transient_retry(|| api.repo(repo.clone()).info())?
}
result => result?,
};
Type information is lost only at the result => result? arm on :3392. A 404 arm there can return the formatted message directly, and refresh_model_at's duplicated {}@{revision} fragment (:2280) then becomes removable, keeping only its unique content ("cannot check … for updates: …; the local version is unchanged (use --offline to skip the check)").
This is offered as placement, not as a correctness claim: the -tp1 naming consequence (a message reporting the originally requested @gb10 after the alias retry also 404s) belongs to the Correctness & Contracts lens; under this lens it is simply a symptom of wrapping outside resolve_revision.
Scope note (state, do not fix here): RevisionClient::revision (flare/src/hub.rs:2130-2151) still returns a bare ureq::Error::StatusCode(404); scan_revisions swallows it (:2171, let Ok(remote) = self.revision(&key.0, &key.1) else { continue; };), and the update check check_core_updates (flare-cli/src/cache_commands.rs:272 (not opened)) rides that path. The cited diagnostic gap therefore narrows for flare download / flare run / flare acquire and Orbit agent downloads rather than closing repo-wide — a scoping sentence in the PR body would be honest and costs nothing.
Suggestion 4 [low, conventions] — The new operator-facing message has no specification clause
The PR changes an operator-visible message but touches no documentation. docs/cli-design.md:920-929 specifies the -tp1 retry:
An explicit `--revision` overrides `@revision` and hardware detection. It accepts
a branch, tag, or commit, and permits downloading on a machine without NVIDIA
hardware. For any platform revision beginning with `gb`, the shared CLI and
desktop downloader tries the corresponding `-tp1` revision if the initial revision
lookup returns HTTP 404; Ampere (`ga*`) revisions are not retried. Flare
— with no mention of what the resulting failure says. AGENTS.md:52-58: "Every repository document has one or both of two purposes: it specifies the architecture… Record unresolved defects, unrun checks, and pending measurements in docs/TODO.txt, not in design documents." A one-clause addition at docs/cli-design.md:924-926 stating that a failed lookup reports the attempted repository@revision while retaining the HTTP status would keep the specification and the message aligned. The related process gap: #489 (the only place this defect is recorded) is a docs PR whose reviewer asked for a docs/TODO.txt entry, and #603 adds none and does not link back.
What is already lean (no action)
-
No dead code, no unused helpers, no leftover scaffolding from the change.
-
No flags, config knobs, environment variables, or option types added; nothing new in
HubOptionsordocs/cli-design.md's option tables. -
No fallback branches or compatibility shims added; the existing
-tp1retry insideresolve_revision(:3381-3391) is untouched and still runs before any diagnostic is added. -
No public surface change:
RevisionLookupError(:3399) is private, so no API or semver concern. -
The test is minimal and proportional:
flare/src/hub.rs:8620-8622if status == 404 { assert!(error.contains(&format!("owner/model@{revision}")), "{error}"); }reuses the existing loop and fixture (
:8601-8625) rather than adding a parallel test, and correctly excludes the 401 case. -
Suggestion 2's predicate and suggestion 3's relocation are independent of suggestion 1; suggestion 1 alone recovers most of the line count.
Open questions
- Is the
source()chain intended for a future consumer (e.g. an Orbit JSON error report that walks causes)? No such consumer exists today inflare/orflare-cli/, and the PR body does not claim one. - Why
resolve_primary_targetrather thanresolve_revision, given the latter has two callers and the same file already hand-writes the identical context for the second (:2279-2280)? Not answerable from the record. - Is
RevisionClient::revision's bare 404 (:2130-2151) deliberately out of scope, given the update check depends on it? - No maintainer statement exists anywhere that this diagnostic is wanted (no issue, no TODO entry, no label); #489's reviewer deferred the defect to
docs/TODO.txt, which this PR does not add. Not resolvable from the record. - No CI checks exist on head
a3ec4b6, so the author's test evidence is unreproduced; the disclosed lockfile caveat (flare/Cargo.lock:597-600pins6d09e9b…vshelios/Cargo.lock:617-619pinning70be62f…) means a reviewer cannot simply run the suite without a temporary realignment.