mold_core/install_error.rs
1//! Errors that can arise while *installing* a catalog (`cv:*`/`hf:*`)
2//! model into the in-memory `state.config.models` view.
3//!
4//! The bool-returning predecessor (`install_catalog_model -> bool`)
5//! collapsed every failure mode into "not installed", so a Civitai
6//! outage and a typo'd model ID surfaced identically to the user. This
7//! enum splits them along the three axes the server's `ApiError`
8//! mapping cares about: transient (502), client-error (404), server bug
9//! / malformed upstream payload (500).
10//!
11//! Lives in `mold-core` so both `mold-server` (HTTP path) and
12//! `mold-cli` (local catalog bridge) can return the same shape; CLI
13//! formats them as `anyhow::Error` user messages.
14
15use thiserror::Error;
16
17#[derive(Debug, Error)]
18pub enum InstallError {
19 /// Live HF/Civitai lookup failed to *reach* the upstream — DNS,
20 /// connect, TLS, or timeout. Maps to HTTP 502 Bad Gateway. The
21 /// inner string carries the upstream error message for the user.
22 #[error("network error contacting catalog upstream: {0}")]
23 Network(String),
24
25 /// Upstream returned 404 (or a normalize failure equivalent to
26 /// "we don't recognize this ID"). Maps to HTTP 404 Not Found.
27 #[error("catalog ID not found upstream: {0}")]
28 NotFound(String),
29
30 /// Upstream returned a payload mold couldn't normalize into a
31 /// `CatalogEntry` — bad shape, missing files, unsupported family.
32 /// Maps to HTTP 500 because it indicates either a mold bug or a
33 /// genuinely broken upstream response.
34 #[error("malformed catalog recipe: {0}")]
35 RecipeMalformed(String),
36}