foundry_config/
warning.rs1use figment::Profile;
2use foundry_compilers::artifacts::remappings::RelativeRemapping;
3use serde::{Deserialize, Serialize};
4use std::{fmt, path::PathBuf};
5
6#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
8#[serde(tag = "type")]
9pub enum Warning {
10 UnknownSection {
12 unknown_section: Profile,
14 source: Option<String>,
16 },
17 NoLocalToml(PathBuf),
19 CouldNotReadToml {
21 path: PathBuf,
23 err: String,
25 },
26 CouldNotWriteToml {
28 path: PathBuf,
30 err: String,
32 },
33 CouldNotFixProfile {
35 path: PathBuf,
37 profile: String,
39 err: String,
41 },
42 DeprecatedKey {
44 old: String,
46 new: String,
49 },
50 UnknownKey {
52 key: String,
54 profile: String,
56 source: String,
58 },
59 UnknownSectionKey {
61 key: String,
63 section: String,
65 source: String,
67 },
68 UnknownProfile {
71 profile: String,
73 },
74 ScopedDependencyRemapping {
77 remapping: RelativeRemapping,
79 resolved: String,
81 },
82}
83
84impl fmt::Display for Warning {
85 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
86 match self {
87 Self::UnknownSection { unknown_section, source } => {
88 let source = source.as_ref().map(|src| format!(" in {src}")).unwrap_or_default();
89 write!(
90 f,
91 "Found unknown config section{source}: [{unknown_section}]\n\
92 This notation for profiles has been deprecated and may result in the profile \
93 not being registered in future versions.\n\
94 Please use [profile.{unknown_section}] instead or run `forge config --fix`."
95 )
96 }
97 Self::NoLocalToml(path) => write!(
98 f,
99 "No local TOML found to fix at {}.\n\
100 Change the current directory to a project path or set the foundry.toml path with \
101 the `FOUNDRY_CONFIG` environment variable",
102 path.display()
103 ),
104
105 Self::CouldNotReadToml { path, err } => {
106 write!(f, "Could not read TOML at {}: {err}", path.display())
107 }
108 Self::CouldNotWriteToml { path, err } => {
109 write!(f, "Could not write TOML to {}: {err}", path.display())
110 }
111 Self::CouldNotFixProfile { path, profile, err } => {
112 write!(f, "Could not fix [{profile}] in TOML at {}: {err}", path.display())
113 }
114 Self::DeprecatedKey { old, new } if new.is_empty() => {
115 write!(f, "Key `{old}` is being deprecated and will be removed in future versions.")
116 }
117 Self::DeprecatedKey { old, new } => {
118 write!(
119 f,
120 "Key `{old}` is being deprecated in favor of `{new}`. It will be removed in future versions."
121 )
122 }
123 Self::UnknownKey { key, profile, source } => {
124 write!(
125 f,
126 "Found unknown `{key}` config for profile `{profile}` defined in {source}."
127 )
128 }
129 Self::UnknownSectionKey { key, section, source } => {
130 write!(
131 f,
132 "Found unknown `{key}` config key in section `{section}` defined in {source}."
133 )
134 }
135 Self::ScopedDependencyRemapping { remapping, resolved } => {
136 let mut global = remapping.clone();
137 let context = global.context.take().unwrap_or_default();
138 let alias = &global.name;
139 write!(
140 f,
141 "Dependency remapping `{global}` now applies only within `{context}`. Root \
142 imports of `{alias}` now resolve to `{resolved}` instead. Adding `{global}` \
143 to your root remappings restores the previous resolution for the whole \
144 project, including other dependencies; to keep a dependency's own target, \
145 also add `<dependency>/:{alias}=<target>`."
146 )
147 }
148 Self::UnknownProfile { profile } => {
149 write!(
150 f,
151 "Selected profile `{profile}` does not exist; falling back to the default profile."
152 )
153 }
154 }
155 }
156}
157
158impl std::error::Error for Warning {}