Trait Handle

Source
pub trait Handle {
    // Required method
    async fn handle(&self, env: &mut Env) -> 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) -> Result

Handles the argument error.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Handle for Error

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) -> Result

Implementors§

Source§

impl Handle for yash_semantics::expansion::Error

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

This implementation handles the error by printing an error message to the standard error and returning 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 Handle for yash_semantics::redir::Error

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.