use std::fmt;
use std::path::PathBuf;
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
Io(std::io::Error),
UnavailableFileCommand {
var: &'static str,
operation: &'static str,
},
MissingEnvFile {
var: &'static str,
path: PathBuf,
},
DelimiterCollision,
ReservedName(String),
InvalidBool {
name: String,
value: String,
},
MissingRequiredInput(String),
ParseInput {
name: String,
reason: String,
},
SummaryTooLarge {
bytes: usize,
},
InvalidName {
name: String,
reason: &'static str,
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Io(e) => write!(f, "i/o error: {e}"),
Error::UnavailableFileCommand { var, operation } => write!(
f,
"`{operation}` requires `{var}`; GitHub retired the stdout fallback for this operation"
),
Error::MissingEnvFile { var, path } => {
write!(f, "{var} points at missing file: {}", path.display())
}
Error::DelimiterCollision => {
f.write_str("generated heredoc delimiter collided with content")
}
Error::ReservedName(name) => {
write!(f, "`{name}` is a reserved variable and cannot be exported")
}
Error::InvalidBool { name, value } => write!(
f,
"input `{name}` is not a valid boolean (got {value:?}); \
expected one of true|True|TRUE|false|False|FALSE"
),
Error::MissingRequiredInput(name) => {
write!(f, "required input `{name}` was not supplied")
}
Error::ParseInput { name, reason } => {
write!(f, "could not parse input `{name}`: {reason}")
}
Error::SummaryTooLarge { bytes } => write!(
f,
"job summary is {bytes} bytes, exceeding the 1 MiB per-step limit"
),
Error::InvalidName { name, reason } => {
write!(f, "invalid name {name:?}: {reason}")
}
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Io(e) => Some(e),
_ => None,
}
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Error::Io(e)
}
}
pub type Result<T> = std::result::Result<T, Error>;