1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! Error types returned by the client.
use std::path::PathBuf;
use crate::types::{TaskId, TaskStatus};
/// Result alias using [`Error`].
pub type Result<T, E = Error> = std::result::Result<T, E>;
/// Errors returned by the client.
#[derive(thiserror::Error, Debug)]
#[non_exhaustive]
pub enum Error {
/// HTTP layer error with no structured API envelope.
#[error("HTTP {status}: {message}")]
Http {
/// HTTP status code.
status: u16,
/// Response body or derived message.
message: String,
},
/// Structured API error envelope (Tripo returns `{code, message, suggestion}`).
#[error("API [{code}] {message}{}", suggestion.as_deref().map(|s| format!(" — {s}")).unwrap_or_default())]
Api {
/// API-specific error code.
code: i32,
/// Human-readable error message.
message: String,
/// Optional suggestion for how to fix the error.
suggestion: Option<String>,
},
/// A task polling loop observed a non-success terminal status.
#[error("task {0} ended with status {1:?}")]
TaskFailed(TaskId, TaskStatus),
/// `wait_for_task` exceeded its timeout.
#[error("timed out waiting for task {0}")]
WaitTimeout(TaskId),
/// `TRIPO_API_KEY` not set and no key passed programmatically.
#[error("missing API key (set TRIPO_API_KEY or pass --api-key)")]
MissingApiKey,
/// API key does not begin with `tsk_`.
#[error("invalid API key (must start with `tsk_`)")]
InvalidApiKey,
/// Download target exists and `overwrite` was not set.
#[error("file already exists: {0} (use --force to overwrite)")]
FileExists(PathBuf),
/// Client-side request validation failed before the request was sent.
#[error("invalid request: {0}")]
InvalidRequest(String),
/// I/O error.
#[error(transparent)]
Io(#[from] std::io::Error),
/// HTTP transport error.
#[error(transparent)]
Reqwest(#[from] reqwest::Error),
/// JSON (de)serialization error.
#[error(transparent)]
Json(#[from] serde_json::Error),
}