pub struct ToolExecutionError { /* private fields */ }Expand description
One public envelope for every tool execution failure.
It carries normalized policy fields, separate operator-facing diagnostics
and model-visible output, and an optional concrete source that can be
downcast. Explicit constructors use the diagnostic message as model-visible
output so deliberately authored validation failures remain actionable.
Self::from_error instead treats an arbitrary source as operator-only and
exposes safe kind-level feedback. Use Self::with_model_feedback or
Self::with_model_output to provide a purpose-built presentation.
Implementations§
Source§impl ToolExecutionError
impl ToolExecutionError
Sourcepub fn report(&self) -> ErrorReport
pub fn report(&self) -> ErrorReport
The wire form of this error.
Source§impl ToolExecutionError
impl ToolExecutionError
Sourcepub fn is_retryable(&self) -> bool
pub fn is_retryable(&self) -> bool
Whether the tool may reasonably be re-run: the explicit override when
one was set, else the kind’s own default
(ToolErrorKind::default_retryable); a kind that leaves it to the
tool (None) is not retryable on the wire.
Source§impl ToolExecutionError
impl ToolExecutionError
Sourcepub fn invalid_args(message: impl Into<String>) -> ToolExecutionError
pub fn invalid_args(message: impl Into<String>) -> ToolExecutionError
Invalid arguments.
Sourcepub fn timeout(message: impl Into<String>) -> ToolExecutionError
pub fn timeout(message: impl Into<String>) -> ToolExecutionError
Timeout.
Sourcepub fn cancelled(message: impl Into<String>) -> ToolExecutionError
pub fn cancelled(message: impl Into<String>) -> ToolExecutionError
Cancellation.
Sourcepub fn not_found(message: impl Into<String>) -> ToolExecutionError
pub fn not_found(message: impl Into<String>) -> ToolExecutionError
Missing tool or resource.
Sourcepub fn permission_denied(message: impl Into<String>) -> ToolExecutionError
pub fn permission_denied(message: impl Into<String>) -> ToolExecutionError
An authorization or permission failure.
This is an ordinary execution error. Use Self::refused when the tool
intentionally declines the operation so hooks and telemetry can preserve
the refusal as a distinct disposition.
Sourcepub fn rate_limited(message: impl Into<String>) -> ToolExecutionError
pub fn rate_limited(message: impl Into<String>) -> ToolExecutionError
Rate limit.
Sourcepub fn provider(message: impl Into<String>) -> ToolExecutionError
pub fn provider(message: impl Into<String>) -> ToolExecutionError
Upstream provider failure.
Sourcepub fn network(message: impl Into<String>) -> ToolExecutionError
pub fn network(message: impl Into<String>) -> ToolExecutionError
Network failure.
Sourcepub fn other(message: impl Into<String>) -> ToolExecutionError
pub fn other(message: impl Into<String>) -> ToolExecutionError
Catch-all failure.
Source§impl ToolExecutionError
impl ToolExecutionError
Sourcepub fn new(
kind: ToolErrorKind,
message: impl Into<String>,
) -> ToolExecutionError
pub fn new( kind: ToolErrorKind, message: impl Into<String>, ) -> ToolExecutionError
Construct an error with an explicit normalized kind.
Sourcepub fn refused(message: impl Into<String>) -> ToolExecutionError
pub fn refused(message: impl Into<String>) -> ToolExecutionError
An intentional, tool-authored refusal.
Refusals use the normalized ToolErrorKind::PermissionDenied kind but
remain distinct from permission failures in ToolResult.
Sourcepub fn from_error<E>(error: E) -> ToolExecutionError
pub fn from_error<E>(error: E) -> ToolExecutionError
Build a safely presented Other error from a concrete source.
The source’s display string remains in Self::message, while the model
sees stable ToolErrorKind::Other feedback. Native targets retain the
downcastable source; WASM drops it. An existing ToolExecutionError
retains its classification and presentation.
Sourcepub fn with_model_feedback(
self,
feedback: impl Into<String>,
) -> ToolExecutionError
pub fn with_model_feedback( self, feedback: impl Into<String>, ) -> ToolExecutionError
Replace the model-visible output with literal text feedback.
Sourcepub fn with_model_output(self, output: ToolOutput) -> ToolExecutionError
pub fn with_model_output(self, output: ToolOutput) -> ToolExecutionError
Replace the model-visible output with canonical JSON or multimodal content.
Sourcepub fn with_retryable(self, retryable: bool) -> ToolExecutionError
pub fn with_retryable(self, retryable: bool) -> ToolExecutionError
Override the retryability hint.
Sourcepub fn with_code(self, code: impl Into<String>) -> ToolExecutionError
pub fn with_code(self, code: impl Into<String>) -> ToolExecutionError
Attach an application/provider code.
Sourcepub fn with_http_status(self, status: u16) -> ToolExecutionError
pub fn with_http_status(self, status: u16) -> ToolExecutionError
Attach an HTTP status.
Sourcepub fn with_source<E>(self, source: E) -> ToolExecutionError
pub fn with_source<E>(self, source: E) -> ToolExecutionError
Preserve a concrete source for later downcasting.
Browser wasm keeps no source (see the field): the call is accepted and the source dropped, so tool code stays target-independent.
Sourcepub const fn kind(&self) -> ToolErrorKind
pub const fn kind(&self) -> ToolErrorKind
Normalized kind.
Sourcepub fn model_feedback(&self) -> Option<&str>
pub fn model_feedback(&self) -> Option<&str>
Literal model feedback, when the presentation is exactly one plain text block.
Use Self::model_output for JSON or multimodal feedback.
Sourcepub fn model_output(&self) -> &ToolOutput
pub fn model_output(&self) -> &ToolOutput
Canonical model-visible presentation for this error.
Sourcepub const fn http_status(&self) -> Option<u16>
pub const fn http_status(&self) -> Option<u16>
HTTP status.
Sourcepub const fn is_refusal(&self) -> bool
pub const fn is_refusal(&self) -> bool
Whether the tool intentionally refused the operation.
Sourcepub fn downcast_ref<E>(&self) -> Option<&E>
pub fn downcast_ref<E>(&self) -> Option<&E>
Downcast the concrete source to E.
Trait Implementations§
Source§impl Clone for ToolExecutionError
impl Clone for ToolExecutionError
Source§fn clone(&self) -> ToolExecutionError
fn clone(&self) -> ToolExecutionError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ToolExecutionError
impl Debug for ToolExecutionError
Source§impl<'de> Deserialize<'de> for ToolExecutionError
impl<'de> Deserialize<'de> for ToolExecutionError
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ToolExecutionError, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ToolExecutionError, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for ToolExecutionError
impl Display for ToolExecutionError
Source§impl Error for ToolExecutionError
impl Error for ToolExecutionError
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()