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 /// A single core model-access policy rejected this identity before any
20 /// installed sidecar or live catalog metadata could activate it.
21 #[error(transparent)]
22 ModelActivation(#[from] crate::ModelActivationError),
23
24 /// Live HF/Civitai lookup failed to *reach* the upstream — DNS,
25 /// connect, TLS, or timeout. Maps to HTTP 502 Bad Gateway. The
26 /// inner string carries the upstream error message for the user.
27 #[error("network error contacting catalog upstream: {0}")]
28 Network(String),
29
30 /// Upstream returned 404 (or a normalize failure equivalent to
31 /// "we don't recognize this ID"). Maps to HTTP 404 Not Found.
32 #[error("catalog ID not found upstream: {0}")]
33 NotFound(String),
34
35 /// Upstream returned a payload mold couldn't normalize into a
36 /// `CatalogEntry` — bad shape, missing files, unsupported family.
37 /// Maps to HTTP 500 because it indicates either a mold bug or a
38 /// genuinely broken upstream response.
39 #[error("malformed catalog recipe: {0}")]
40 RecipeMalformed(String),
41}