foundry_config/
warning.rs1use figment::Profile;
2use serde::{Deserialize, Serialize};
3use std::{fmt, path::PathBuf};
4
5#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
7#[serde(tag = "type")]
8pub enum Warning {
9 UnknownSection {
11 unknown_section: Profile,
13 source: Option<String>,
15 },
16 NoLocalToml(PathBuf),
18 CouldNotReadToml {
20 path: PathBuf,
22 err: String,
24 },
25 CouldNotWriteToml {
27 path: PathBuf,
29 err: String,
31 },
32 CouldNotFixProfile {
34 path: PathBuf,
36 profile: String,
38 err: String,
40 },
41 DeprecatedKey {
43 old: String,
45 new: String,
48 },
49 UnknownKey {
51 key: String,
53 profile: String,
55 source: String,
57 },
58 UnknownSectionKey {
60 key: String,
62 section: String,
64 source: String,
66 },
67 UnknownProfile {
70 profile: String,
72 },
73}
74
75impl fmt::Display for Warning {
76 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
77 match self {
78 Self::UnknownSection { unknown_section, source } => {
79 let source = source.as_ref().map(|src| format!(" in {src}")).unwrap_or_default();
80 write!(
81 f,
82 "Found unknown config section{source}: [{unknown_section}]\n\
83 This notation for profiles has been deprecated and may result in the profile \
84 not being registered in future versions.\n\
85 Please use [profile.{unknown_section}] instead or run `forge config --fix`."
86 )
87 }
88 Self::NoLocalToml(path) => write!(
89 f,
90 "No local TOML found to fix at {}.\n\
91 Change the current directory to a project path or set the foundry.toml path with \
92 the `FOUNDRY_CONFIG` environment variable",
93 path.display()
94 ),
95
96 Self::CouldNotReadToml { path, err } => {
97 write!(f, "Could not read TOML at {}: {err}", path.display())
98 }
99 Self::CouldNotWriteToml { path, err } => {
100 write!(f, "Could not write TOML to {}: {err}", path.display())
101 }
102 Self::CouldNotFixProfile { path, profile, err } => {
103 write!(f, "Could not fix [{profile}] in TOML at {}: {err}", path.display())
104 }
105 Self::DeprecatedKey { old, new } if new.is_empty() => {
106 write!(f, "Key `{old}` is being deprecated and will be removed in future versions.")
107 }
108 Self::DeprecatedKey { old, new } => {
109 write!(
110 f,
111 "Key `{old}` is being deprecated in favor of `{new}`. It will be removed in future versions."
112 )
113 }
114 Self::UnknownKey { key, profile, source } => {
115 write!(
116 f,
117 "Found unknown `{key}` config for profile `{profile}` defined in {source}."
118 )
119 }
120 Self::UnknownSectionKey { key, section, source } => {
121 write!(
122 f,
123 "Found unknown `{key}` config key in section `{section}` defined in {source}."
124 )
125 }
126 Self::UnknownProfile { profile } => {
127 write!(
128 f,
129 "Selected profile `{profile}` does not exist; falling back to the default profile."
130 )
131 }
132 }
133 }
134}
135
136impl std::error::Error for Warning {}