#![allow(missing_docs, clippy::redundant_closure)]
use compose_yml::v2 as dc;
use std::ffi::OsString;
use std::io;
use std::path::{PathBuf, StripPrefixError};
use std::string::FromUtf8Error;
use crate::project::PROJECT_CONFIG_PATH;
use crate::version;
error_chain! {
foreign_links {
Compose(dc::Error);
Docker(boondock::errors::Error);
Utf8Error(FromUtf8Error);
Glob(glob::GlobError);
GlobPattern(glob::PatternError);
Io(io::Error);
StripPrefix(StripPrefixError);
}
errors {
CommandFailed(command: Vec<OsString>) {
description("error running external command")
display("error running '{}'", command_to_string(&command))
}
CouldNotGetRuntimeState {
description("error getting the project's state from Docker")
display("error getting the project's state from Docker")
}
CouldNotParse(parsing_as: &'static str, input: String) {
description("failed to parse string")
display("failed to parse '{}' as {}", &input, parsing_as)
}
CouldNotReadDirectory(path: PathBuf) {
description("could not read a directory")
display("could not read '{}'", path.display())
}
CouldNotReadFile(path: PathBuf) {
description("could not read a file")
display("could not read '{}'", path.display())
}
CouldNotWriteFile(path: PathBuf) {
description("could not write to a file")
display("could not write to '{}'", path.display())
}
FeatureDisabled {
description("feature disabled at compile time")
display("this feature was disabled when the application was \
compiled (you may want to rebuild from source)")
}
MismatchedVersion(required: semver::VersionReq) {
description("incompatible cage version")
display("{} specifies cage {}, but you have {}",
PROJECT_CONFIG_PATH.display(), &required, version())
}
OutputDirectoryExists(path: PathBuf) {
description("output directory already exists")
display("output directory {} already exists (please delete)", path.display())
}
PluginFailed(plugin: String) {
description("plugin failed")
display("plugin '{}' failed", &plugin)
}
ServicesAddedInTarget(base: PathBuf, target: PathBuf, names: Vec<String>) {
description("services present in target but not in base")
display("services {:?} present in {} but not in {}",
&names, base.display(), target.display())
}
UnknownLibKey(lib_key: String) {
description("unknown library")
display("no library '{}' defined in `config/sources.yml`", &lib_key)
}
LibHasRepoSubdirectory(lib_key: String) {
description("invalid library context URL")
display("library '{}' may not specify a subdirectory in its git URL", &lib_key)
}
UnknownTarget(target_name: String) {
description("unknown target")
display("unknown target '{}'", &target_name)
}
UnknownPodOrService(pod_or_service_name: String) {
description("unknown pod or service")
display("unknown pod or service '{}'", &pod_or_service_name)
}
UnknownService(service_name: String) {
description("unknown service")
display("unknown service '{}'", &service_name)
}
UnknownSource(source_alias: String) {
description("unknown source alias")
display("unknown short alias '{}' for source tree (try `cage \
source ls`)",
&source_alias)
}
VaultError(url: String) {
description("an error occurred talking to a Vault server")
display("an error occurred talking to the Vault server at {}", &url)
}
}
}
impl ErrorKind {
pub fn parse<S>(parsing_as: &'static str, input: S) -> ErrorKind
where
S: Into<String>,
{
ErrorKind::CouldNotParse(parsing_as, input.into())
}
}
fn command_to_string(command: &[OsString]) -> String {
let cmd: Vec<_> = command
.iter()
.map(|s| s.to_string_lossy().into_owned())
.collect();
cmd.join(" ")
}