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}
59
60impl fmt::Display for Warning {
61 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62 match self {
63 Self::UnknownSection { unknown_section, source } => {
64 let source = source.as_ref().map(|src| format!(" in {src}")).unwrap_or_default();
65 write!(
66 f,
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 }
73 Self::NoLocalToml(path) => write!(
74 f,
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 ),
80
81 Self::CouldNotReadToml { path, err } => {
82 write!(f, "Could not read TOML at {}: {err}", path.display())
83 }
84 Self::CouldNotWriteToml { path, err } => {
85 write!(f, "Could not write TOML to {}: {err}", path.display())
86 }
87 Self::CouldNotFixProfile { path, profile, err } => {
88 write!(f, "Could not fix [{profile}] in TOML at {}: {err}", path.display())
89 }
90 Self::DeprecatedKey { old, new } if new.is_empty() => {
91 write!(f, "Key `{old}` is being deprecated and will be removed in future versions.")
92 }
93 Self::DeprecatedKey { old, new } => {
94 write!(
95 f,
96 "Key `{old}` is being deprecated in favor of `{new}`. It will be removed in future versions."
97 )
98 }
99 Self::UnknownKey { key, profile, source } => {
100 write!(
101 f,
102 "Found unknown `{key}` config for profile `{profile}` defined in {source}."
103 )
104 }
105 }
106 }
107}
108
109impl std::error::Error for Warning {}