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>) -> Self
pub fn new(kind: ToolErrorKind, message: impl Into<String>) -> Self
Construct an error with an explicit normalized kind.
Sourcepub fn invalid_args(message: impl Into<String>) -> Self
pub fn invalid_args(message: impl Into<String>) -> Self
Invalid arguments.
Sourcepub fn permission_denied(message: impl Into<String>) -> Self
pub fn permission_denied(message: impl Into<String>) -> Self
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>) -> Self
pub fn refused(message: impl Into<String>) -> Self
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>) -> Self
pub fn rate_limited(message: impl Into<String>) -> Self
Rate limit.
Sourcepub fn from_error<E>(error: E) -> Self
pub fn from_error<E>(error: E) -> Self
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>) -> Self
pub fn with_model_feedback(self, feedback: impl Into<String>) -> Self
Replace the model-visible output with literal text feedback.
Sourcepub fn with_model_output(self, output: ToolOutput) -> Self
pub fn with_model_output(self, output: ToolOutput) -> Self
Replace the model-visible output with canonical JSON or multimodal content.
Sourcepub fn redact_model_feedback(self) -> Self
pub fn redact_model_feedback(self) -> Self
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) -> Self
pub fn with_retryable(self, retryable: bool) -> Self
Override the retryability hint.
Sourcepub fn with_http_status(self, status: u16) -> Self
pub fn with_http_status(self, status: u16) -> Self
Attach an HTTP status.
Sourcepub fn with_source<E>(self, source: E) -> Self
pub fn with_source<E>(self, source: E) -> Self
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()
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
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.