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}
50
51impl fmt::Display for Warning {
52 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53 match self {
54 Self::UnknownSection { unknown_section, source } => {
55 let source = source.as_ref().map(|src| format!(" in {src}")).unwrap_or_default();
56 write!(
57 f,
58 "Found unknown config section{source}: [{unknown_section}]\n\
59 This notation for profiles has been deprecated and may result in the profile \
60 not being registered in future versions.\n\
61 Please use [profile.{unknown_section}] instead or run `forge config --fix`."
62 )
63 }
64 Self::NoLocalToml(path) => write!(
65 f,
66 "No local TOML found to fix at {}.\n\
67 Change the current directory to a project path or set the foundry.toml path with \
68 the `FOUNDRY_CONFIG` environment variable",
69 path.display()
70 ),
71
72 Self::CouldNotReadToml { path, err } => {
73 write!(f, "Could not read TOML at {}: {err}", path.display())
74 }
75 Self::CouldNotWriteToml { path, err } => {
76 write!(f, "Could not write TOML to {}: {err}", path.display())
77 }
78 Self::CouldNotFixProfile { path, profile, err } => {
79 write!(f, "Could not fix [{profile}] in TOML at {}: {err}", path.display())
80 }
81 Self::DeprecatedKey { old, new } if new.is_empty() => {
82 write!(f, "Key `{old}` is being deprecated and will be removed in future versions.")
83 }
84 Self::DeprecatedKey { old, new } => {
85 write!(
86 f,
87 "Key `{old}` is being deprecated in favor of `{new}`. It will be removed in future versions."
88 )
89 }
90 }
91 }
92}
93
94impl std::error::Error for Warning {}