Files
porthole/src/error.rs

64 lines
1.6 KiB
Rust

use thiserror::Error;
#[derive(Error, Debug)]
pub enum PortholeError {
#[error(
"invalid name '{0}' (use 1-64 chars: letters, digits, '_' or '-'; \
must start with a letter or digit)"
)]
InvalidName(String),
#[error("no profile named '{0}'")]
NotFound(String),
#[error("profile '{0}' already exists (use 'edit' to modify it)")]
AlreadyExists(String),
#[error("exactly one of -l/--local, -r/--remote, -d/--dynamic is required")]
NoMappingKind,
#[error("only one of -l/--local, -r/--remote, -d/--dynamic may be given")]
MultipleMappingKinds,
#[error("invalid forward spec '{0}': expected [BIND:]PORT:HOST:PORT (or [BIND:]PORT for -d)")]
InvalidMapping(String),
#[error("invalid --via hop '{0}': expected [USER@]HOST[:PORT]")]
InvalidVia(String),
#[error("--via is required: at least one hop (connection target)")]
NoViaHosts,
#[error("nothing to do: {0}")]
NothingToDo(String),
#[error("'{0}' failed to start: {1}")]
OpenFailed(String, String),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error("state file error: {0}")]
Serde(String),
}
pub type Result<T> = std::result::Result<T, PortholeError>;
impl From<toml::de::Error> for PortholeError {
fn from(e: toml::de::Error) -> Self {
PortholeError::Serde(e.to_string())
}
}
impl From<toml::ser::Error> for PortholeError {
fn from(e: toml::ser::Error) -> Self {
PortholeError::Serde(e.to_string())
}
}
impl From<serde_json::Error> for PortholeError {
fn from(e: serde_json::Error) -> Self {
PortholeError::Serde(e.to_string())
}
}