Skip to main content

entrenar/hf_pipeline/publish/
result.rs

1//! Publishing result and error types
2
3use std::fmt;
4
5/// Successful publish result
6#[derive(Clone, Debug)]
7pub struct PublishResult {
8    /// Repository URL on HuggingFace
9    pub repo_url: String,
10    /// Repository ID
11    pub repo_id: String,
12    /// Number of files uploaded
13    pub files_uploaded: usize,
14    /// Whether the model card was generated
15    pub model_card_generated: bool,
16}
17
18impl fmt::Display for PublishResult {
19    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20        write!(
21            f,
22            "Published to {} ({} files{})",
23            self.repo_url,
24            self.files_uploaded,
25            if self.model_card_generated { " + model card" } else { "" }
26        )
27    }
28}
29
30/// Errors during publishing
31#[derive(Debug, thiserror::Error)]
32pub enum PublishError {
33    /// Repository creation failed
34    #[error("Failed to create repository '{repo_id}': {message}")]
35    RepoCreationFailed { repo_id: String, message: String },
36
37    /// File upload failed
38    #[error("Failed to upload '{path}': {message}")]
39    UploadFailed { path: String, message: String },
40
41    /// Authentication required
42    #[error("Authentication required: set HF_TOKEN or use with_token()")]
43    AuthRequired,
44
45    /// Invalid repository ID
46    #[error("Invalid repository ID '{repo_id}': must be 'owner/name'")]
47    InvalidRepoId { repo_id: String },
48
49    /// HTTP error
50    #[error("HTTP error: {message}")]
51    Http { message: String },
52
53    /// IO error
54    #[error("IO error: {0}")]
55    Io(#[from] std::io::Error),
56
57    /// Serialization error
58    #[error("Serialization error: {0}")]
59    Serialization(String),
60}