pub struct ProviderError { /* private fields */ }Expand description
Unified error returned by every provider operation.
Use the is_*() helpers to branch on cause. The underlying variant is
intentionally hidden so we can add new failure modes without a breaking
change.
Internally boxed so Result<T, ProviderError> stays one machine word
in the Err slot.
§Examples
use llmsdk_provider::ProviderError;
let err = ProviderError::no_such_model("gpt-foo", "languageModel");
assert!(err.is_no_such_model());
assert_eq!(err.model_id(), Some("gpt-foo"));Implementations§
Source§impl ProviderError
impl ProviderError
Sourcepub fn api_call(url: impl Into<String>, message: impl Into<String>) -> Self
pub fn api_call(url: impl Into<String>, message: impl Into<String>) -> Self
Build an HTTP API call error.
is_retryable is true by default for 408 / 409 / 429 / 5xx,
matching ai-sdk’s APICallError defaults. Use Self::api_call_builder
for full control.
Sourcepub fn api_call_builder(
url: impl Into<String>,
message: impl Into<String>,
) -> ApiCallErrorBuilder
pub fn api_call_builder( url: impl Into<String>, message: impl Into<String>, ) -> ApiCallErrorBuilder
Open a builder for an API call error with optional fields.
Sourcepub fn invalid_argument(
argument: impl Into<String>,
message: impl Into<String>,
) -> Self
pub fn invalid_argument( argument: impl Into<String>, message: impl Into<String>, ) -> Self
Build an invalid-argument error for a public parameter.
Sourcepub fn invalid_prompt(message: impl Into<String>) -> Self
pub fn invalid_prompt(message: impl Into<String>) -> Self
Build an invalid-prompt error.
Sourcepub fn type_validation(
path: impl Into<String>,
value: JsonValue,
message: impl Into<String>,
) -> Self
pub fn type_validation( path: impl Into<String>, value: JsonValue, message: impl Into<String>, ) -> Self
Build a type-validation error for a JSON path.
Sourcepub fn json_parse(text: impl Into<String>, message: impl Into<String>) -> Self
pub fn json_parse(text: impl Into<String>, message: impl Into<String>) -> Self
Build a JSON parse error.
Sourcepub fn empty_response_body() -> Self
pub fn empty_response_body() -> Self
The provider returned an empty body where content was expected.
Sourcepub fn no_content_generated() -> Self
pub fn no_content_generated() -> Self
The provider returned successfully but produced no usable content.
Sourcepub fn no_such_model(
model_id: impl Into<String>,
model_type: impl Into<String>,
) -> Self
pub fn no_such_model( model_id: impl Into<String>, model_type: impl Into<String>, ) -> Self
No such model id for the given model type (languageModel, …).
Sourcepub fn unsupported(functionality: impl Into<String>) -> Self
pub fn unsupported(functionality: impl Into<String>) -> Self
The provider does not support the requested functionality.
Sourcepub fn load_api_key(message: impl Into<String>) -> Self
pub fn load_api_key(message: impl Into<String>) -> Self
Could not load an API key from the environment / config.
Sourcepub fn too_many_embedding_values(max: usize, actual: usize) -> Self
pub fn too_many_embedding_values(max: usize, actual: usize) -> Self
Too many embedding inputs passed in a single call.
Sourcepub fn is_api_call(&self) -> bool
pub fn is_api_call(&self) -> bool
True for API-level HTTP failures.
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
True when the failure should be retried.
Currently only Self::is_api_call errors carry retry information;
all others return false.
Sourcepub fn is_no_such_model(&self) -> bool
pub fn is_no_such_model(&self) -> bool
True when the error reports an unknown model id.
Sourcepub fn is_unsupported(&self) -> bool
pub fn is_unsupported(&self) -> bool
True when the error reports unsupported functionality.
Sourcepub fn status_code(&self) -> Option<u16>
pub fn status_code(&self) -> Option<u16>
HTTP status code when Self::is_api_call.
Sourcepub fn response_body(&self) -> Option<&str>
pub fn response_body(&self) -> Option<&str>
Captured response body when Self::is_api_call.
Returned by HTTP transports that read the full body before raising
the error; otherwise None.
Sourcepub fn url(&self) -> Option<&str>
pub fn url(&self) -> Option<&str>
Request URL when Self::is_api_call.
Sourcepub fn model_id(&self) -> Option<&str>
pub fn model_id(&self) -> Option<&str>
Model id when Self::is_no_such_model.
Trait Implementations§
Source§impl Debug for ProviderError
impl Debug for ProviderError
Source§impl Display for ProviderError
impl Display for ProviderError
Source§impl Error for ProviderError
impl Error for ProviderError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()