pub enum OpencodeError {
Api {
status: u16,
headers: Option<Box<HeaderMap>>,
body: Option<Box<Value>>,
message: String,
},
Connection {
message: String,
source: Option<Box<dyn Error + Send + Sync>>,
},
Timeout,
UserAbort,
Serialization(Error),
Http(Box<dyn Error + Send + Sync>),
}Expand description
Primary error type for the OpenCode SDK.
Models the JS SDK’s error hierarchy as a flat enum with variants for API errors (with status codes), connection errors, timeouts, user aborts, serialization errors, and generic HTTP transport errors.
Variants§
Api
An API error returned by the server with an HTTP status code.
Connection
A connection-level error (DNS, TCP, TLS, etc.).
Timeout
The request timed out.
UserAbort
The user aborted the request.
Serialization(Error)
Failed to serialize or deserialize JSON.
Http(Box<dyn Error + Send + Sync>)
An opaque HTTP transport error.
Implementations§
Source§impl OpencodeError
impl OpencodeError
Sourcepub const fn status(&self) -> Option<u16>
pub const fn status(&self) -> Option<u16>
Returns the HTTP status code if this is an Api variant.
Sourcepub const fn is_retryable(&self) -> bool
pub const fn is_retryable(&self) -> bool
Whether this error should be retried.
Mirrors the JS SDK logic:
- Status 408, 409, 429, >= 500 → retryable
- Connection errors and timeouts → retryable
- Everything else → not retryable
Sourcepub const fn is_timeout(&self) -> bool
pub const fn is_timeout(&self) -> bool
Whether this error represents a timeout.
Sourcepub fn bad_request(
headers: Option<HeaderMap>,
body: Option<Value>,
message: impl Into<String>,
) -> Self
pub fn bad_request( headers: Option<HeaderMap>, body: Option<Value>, message: impl Into<String>, ) -> Self
400 Bad Request
Sourcepub fn authentication(
headers: Option<HeaderMap>,
body: Option<Value>,
message: impl Into<String>,
) -> Self
pub fn authentication( headers: Option<HeaderMap>, body: Option<Value>, message: impl Into<String>, ) -> Self
401 Authentication Error
Sourcepub fn permission_denied(
headers: Option<HeaderMap>,
body: Option<Value>,
message: impl Into<String>,
) -> Self
pub fn permission_denied( headers: Option<HeaderMap>, body: Option<Value>, message: impl Into<String>, ) -> Self
403 Permission Denied
Sourcepub fn not_found(
headers: Option<HeaderMap>,
body: Option<Value>,
message: impl Into<String>,
) -> Self
pub fn not_found( headers: Option<HeaderMap>, body: Option<Value>, message: impl Into<String>, ) -> Self
404 Not Found
Sourcepub fn conflict(
headers: Option<HeaderMap>,
body: Option<Value>,
message: impl Into<String>,
) -> Self
pub fn conflict( headers: Option<HeaderMap>, body: Option<Value>, message: impl Into<String>, ) -> Self
409 Conflict
Sourcepub fn unprocessable_entity(
headers: Option<HeaderMap>,
body: Option<Value>,
message: impl Into<String>,
) -> Self
pub fn unprocessable_entity( headers: Option<HeaderMap>, body: Option<Value>, message: impl Into<String>, ) -> Self
422 Unprocessable Entity
Sourcepub fn rate_limit(
headers: Option<HeaderMap>,
body: Option<Value>,
message: impl Into<String>,
) -> Self
pub fn rate_limit( headers: Option<HeaderMap>, body: Option<Value>, message: impl Into<String>, ) -> Self
429 Rate Limit
Trait Implementations§
Source§impl Debug for OpencodeError
impl Debug for OpencodeError
Source§impl Display for OpencodeError
impl Display for OpencodeError
Source§impl Error for OpencodeError
impl Error for OpencodeError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for OpencodeError
impl !RefUnwindSafe for OpencodeError
impl Send for OpencodeError
impl Sync for OpencodeError
impl Unpin for OpencodeError
impl !UnwindSafe for OpencodeError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more