1use figment::Profile;
2use serde::{Deserialize, Serialize};
3use std::{fmt, path::PathBuf};
45/// Warnings emitted during loading or managing Configuration
6#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
7#[serde(tag = "type")]
8pub enum Warning {
9/// An unknown section was encountered in a TOML file
10UnknownSection {
11/// The unknown key
12unknown_section: Profile,
13/// The source where the key was found
14source: Option<String>,
15 },
16/// No local TOML file found, with location tried
17NoLocalToml(PathBuf),
18/// Could not read TOML
19CouldNotReadToml {
20/// The path of the TOML file
21path: PathBuf,
22/// The error message that occurred
23err: String,
24 },
25/// Could not write TOML
26CouldNotWriteToml {
27/// The path of the TOML file
28path: PathBuf,
29/// The error message that occurred
30err: String,
31 },
32/// Invalid profile. Profile should be a table
33CouldNotFixProfile {
34/// The path of the TOML file
35path: PathBuf,
36/// The profile to be fixed
37profile: String,
38/// The error message that occurred
39err: String,
40 },
41/// Deprecated key.
42DeprecatedKey {
43/// The key being deprecated
44old: String,
45/// The new key replacing the deprecated one if not empty, otherwise, meaning the old one
46 /// is being removed completely without replacement
47new: String,
48 },
49/// An unknown key was encountered in a profile in a TOML file
50UnknownKey {
51/// The unknown key name
52key: String,
53/// The profile where the key was found, if applicable
54profile: String,
55/// The config file where the key was found
56source: String,
57 },
58}
5960impl fmt::Displayfor Warning {
61fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62match self {
63Self::UnknownSection { unknown_section, source } => {
64let source = source.as_ref().map(|src| format!(" in {src}")).unwrap_or_default();
65write!(
66f,
67"Found unknown config section{source}: [{unknown_section}]\n\
68 This notation for profiles has been deprecated and may result in the profile \
69 not being registered in future versions.\n\
70 Please use [profile.{unknown_section}] instead or run `forge config --fix`."
71)
72 }
73Self::NoLocalToml(path) => write!(
74f,
75"No local TOML found to fix at {}.\n\
76 Change the current directory to a project path or set the foundry.toml path with \
77 the `FOUNDRY_CONFIG` environment variable",
78 path.display()
79 ),
8081Self::CouldNotReadToml { path, err } => {
82write!(f, "Could not read TOML at {}: {err}", path.display())
83 }
84Self::CouldNotWriteToml { path, err } => {
85write!(f, "Could not write TOML to {}: {err}", path.display())
86 }
87Self::CouldNotFixProfile { path, profile, err } => {
88write!(f, "Could not fix [{profile}] in TOML at {}: {err}", path.display())
89 }
90Self::DeprecatedKey { old, new } if new.is_empty() => {
91write!(f, "Key `{old}` is being deprecated and will be removed in future versions.")
92 }
93Self::DeprecatedKey { old, new } => {
94write!(
95f,
96"Key `{old}` is being deprecated in favor of `{new}`. It will be removed in future versions."
97)
98 }
99Self::UnknownKey { key, profile, source } => {
100write!(
101f,
102"Found unknown `{key}` config for profile `{profile}` defined in {source}."
103)
104 }
105 }
106 }
107}
108109impl std::error::Errorfor Warning {}