foundry_config/
warning.rsuse figment::Profile;
use serde::{Deserialize, Serialize};
use std::{fmt, path::PathBuf};
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum Warning {
UnknownSection {
unknown_section: Profile,
source: Option<String>,
},
NoLocalToml(PathBuf),
CouldNotReadToml {
path: PathBuf,
err: String,
},
CouldNotWriteToml {
path: PathBuf,
err: String,
},
CouldNotFixProfile {
path: PathBuf,
profile: String,
err: String,
},
DeprecatedKey {
old: String,
new: String,
},
}
impl fmt::Display for Warning {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::UnknownSection { unknown_section, source } => {
let source = source.as_ref().map(|src| format!(" in {src}")).unwrap_or_default();
write!(
f,
"Found unknown config section{source}: [{unknown_section}]\n\
This notation for profiles has been deprecated and may result in the profile \
not being registered in future versions.\n\
Please use [profile.{unknown_section}] instead or run `forge config --fix`."
)
}
Self::NoLocalToml(path) => write!(
f,
"No local TOML found to fix at {}.\n\
Change the current directory to a project path or set the foundry.toml path with \
the `FOUNDRY_CONFIG` environment variable",
path.display()
),
Self::CouldNotReadToml { path, err } => {
write!(f, "Could not read TOML at {}: {err}", path.display())
}
Self::CouldNotWriteToml { path, err } => {
write!(f, "Could not write TOML to {}: {err}", path.display())
}
Self::CouldNotFixProfile { path, profile, err } => {
write!(f, "Could not fix [{profile}] in TOML at {}: {err}", path.display())
}
Self::DeprecatedKey { old, new } if new.is_empty() => {
write!(f, "Key `{old}` is being deprecated and will be removed in future versions.")
}
Self::DeprecatedKey { old, new } => {
write!(f, "Key `{old}` is being deprecated in favor of `{new}`. It will be removed in future versions.")
}
}
}
}
impl std::error::Error for Warning {}