Skip to main content

Handle

Trait Handle 

Source
pub trait Handle<S> {
    // Required method
    async fn handle(&self, env: &mut Env<S>) -> Result;
}
Expand description

Error handler.

Most errors in the shell are handled by printing an error message to the standard error and returning a non-zero exit status. This trait provides a standard interface for implementing that behavior.

Required Methods§

Source

async fn handle(&self, env: &mut Env<S>) -> Result

Handles the argument error.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<S> Handle<S> for Error
where S: Isatty + WriteAll,

Prints an error message.

This implementation handles the error by printing an error message to the standard error and returning Divert::Interrupt(Some(exit_status)), where exit_status is ExitStatus::ERROR if the error cause is a syntax error or the error location is Source::DotScript, or ExitStatus::READ_ERROR otherwise. Note that other POSIX-compliant implementations may use different non-zero exit statuses instead of ExitStatus::ERROR.

Source§

async fn handle(&self, env: &mut Env<S>) -> Result

Implementors§

Source§

impl<S> Handle<S> for yash_semantics::expansion::Error
where S: Isatty + WriteAll,

Prints an error message and returns a divert result indicating a non-zero exit status.

If the error cause is ErrorCause::Interrupted, this implementation returns Break(Divert::Interrupt(Some(exit_status))) without printing an error message, where exit_status is the exit status contained in the error cause.

Otherwise, this implementation prints an error message to the standard error and returns Divert::Interrupt(Some(ExitStatus::ERROR)). If the ErrExit option is set, Divert::Exit(Some(ExitStatus::ERROR)) is returned instead.

Note that other POSIX-compliant implementations may use different non-zero exit statuses.

Source§

impl<S> Handle<S> for yash_semantics::redir::Error
where S: Isatty + WriteAll,

Prints an error message and sets the exit status to non-zero.

This implementation handles a redirection error by printing an error message to the standard error and setting the exit status to ExitStatus::ERROR. Note that other POSIX-compliant implementations may use different non-zero exit statuses.

This implementation does not return Divert::Interrupt because a redirection error does not always mean an interrupt. The shell should interrupt only on a redirection error during the execution of a special built-in. The caller is responsible for checking the condition and interrupting accordingly.