Skip to main content

suno_core/
error.rs

1//! Error types for the Suno engine.
2
3use std::time::Duration;
4
5/// An error raised by the engine.
6#[derive(Debug, thiserror::Error)]
7pub enum Error {
8    /// The token was rejected, or no session or JWT could be obtained.
9    #[error("authentication failed: {0}")]
10    Auth(String),
11    /// A transport failure talking to Clerk or the Suno API.
12    #[error("could not connect: {0}")]
13    Connection(String),
14    /// The Suno API returned an unexpected status or body.
15    #[error("api error: {0}")]
16    Api(String),
17    /// The Suno API returned `404 Not Found` for the requested resource.
18    ///
19    /// Distinct from [`Api`](Self::Api) so a caller can treat a genuine absence
20    /// (a clip with no parent) as `None` without also swallowing a transient
21    /// `5xx`, which must surface as a real error.
22    #[error("not found: {0}")]
23    NotFound(String),
24    /// The Suno API rate-limited the request, with the server's `Retry-After`
25    /// hint in whole seconds when it sent one (it usually does not).
26    #[error("rate limited")]
27    RateLimited { retry_after: Option<Duration> },
28    /// Reading or writing audio metadata tags failed.
29    #[error("tagging failed: {0}")]
30    Tag(String),
31    /// The config file could not be parsed or failed validation.
32    #[error("config error: {0}")]
33    Config(String),
34}
35
36/// A `Result` whose error is the engine [`Error`].
37pub type Result<T> = std::result::Result<T, Error>;