use super::{MAX_ATOMS, MAX_DEPTH, MAX_DIRS};
use crate::lexer::LexError;
#[derive(Debug, thiserror::Error)]
pub(crate) enum ClassifyError {
#[error(transparent)]
Lex(#[from] LexError),
#[error("command nesting deeper than {MAX_DEPTH}")]
TooDeep,
#[error("command expands to more than {MAX_ATOMS} actions")]
TooManyActions,
#[error("cannot interpret `{option}` for `{program}`")]
ShellOption { program: String, option: String },
#[error("`{program} {option}` runs code from a file or module the command line names")]
LoadsCode { program: String, option: String },
#[error("`{0}` names a path relative to a directory that is not known")]
UnknownDirectory(String),
#[error("`cd` may lead to more than {MAX_DIRS} directories")]
TooManyDirectories,
#[error("unbalanced parentheses")]
UnbalancedParens,
#[error("the shell runs text from `{0}` that the command line does not show")]
UnknownStdin(String),
#[error("`{0}` depends on a variable whose value is not known")]
UnknownValue(String),
#[error("a variable set on the line may hold more than {MAX_DIRS} combinations of values")]
TooManyValues,
}
impl ClassifyError {
pub(crate) fn asks(&self) -> bool {
matches!(
self,
Self::Lex(_)
| Self::TooDeep
| Self::TooManyActions
| Self::TooManyDirectories
| Self::TooManyValues
)
}
}