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 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 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 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 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.
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 available as the operator-facing
Self::message and the source remains downcastable, but the model sees
only the stable feedback for ToolErrorKind::Other. Passing an existing
ToolExecutionError preserves 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 redact_model_feedback(self) -> ToolExecutionError
pub fn redact_model_feedback(self) -> ToolExecutionError
Replace potentially sensitive diagnostics with stable, kind-specific model feedback.
Explicit error constructors make messages model-visible by default to
keep failures actionable. Call this when an explicitly constructed
error’s operator diagnostic may contain secrets; Self::from_error
already uses this safe presentation for arbitrary source errors.
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.
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 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()
Source§impl From<MissingToolContext> for ToolExecutionError
impl From<MissingToolContext> for ToolExecutionError
Source§fn from(error: MissingToolContext) -> Self
fn from(error: MissingToolContext) -> Self
Auto Trait Implementations§
impl !RefUnwindSafe for ToolExecutionError
impl !UnwindSafe for ToolExecutionError
impl Freeze for ToolExecutionError
impl Send for ToolExecutionError
impl Sync for ToolExecutionError
impl Unpin for ToolExecutionError
impl UnsafeUnpin for ToolExecutionError
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
impl<T> CloneDebuggableStorage for Twhere
T: DebuggableStorage + Clone,
fn clone_storage(&self) -> Box<dyn CloneDebuggableStorage>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CloneableStorage for T
impl<T> CloneableStorage for T
fn clone_storage(&self) -> Box<dyn CloneableStorage>
impl<T> DebuggableStorage for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.