Skip to content

Commit

Permalink
feat: show config file path when deprecated keys are found (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
boxdot authored Mar 2, 2025
1 parent 046a816 commit 826f2dc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
19 changes: 15 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ impl DeveloperConfig {
#[derive(Debug, Clone)]
pub(crate) struct LoadedConfig {
pub(crate) config: Config,
pub(crate) deprecated_keys: Vec<DeprecatedConfigKey>,
pub(crate) deprecated_keys: DeprecatedKeys,
}

#[derive(Debug, Clone)]
pub(crate) struct DeprecatedKeys {
pub(crate) file_path: PathBuf,
pub(crate) keys: Vec<DeprecatedConfigKey>,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -141,28 +147,33 @@ impl Config {
}

fn load(path: impl AsRef<Path>) -> anyhow::Result<LoadedConfig> {
let path = path.as_ref();
let content = std::fs::read_to_string(path)?;
let config = toml::de::from_str(&content)?;

// check for deprecated keys
let config_value: toml::Value = toml::de::from_str(&content)?;
let mut deprecated_keys = Vec::new();
let mut keys = Vec::new();
if config_value
.get("sqlite")
.map(|v| v.get("enabled").is_some())
.unwrap_or(false)
{
deprecated_keys.push(DeprecatedConfigKey {
keys.push(DeprecatedConfigKey {
key: "sqlite.enabled",
message: "sqlite is now enabled by default",
});
}
if config_value.get("data_path").is_some() {
deprecated_keys.push(DeprecatedConfigKey {
keys.push(DeprecatedConfigKey {
key: "data_path",
message: "is not used anymore, and is migrated to sqlite.url",
});
}
let deprecated_keys = DeprecatedKeys {
file_path: path.to_path_buf(),
keys,
};

Ok(LoadedConfig {
config,
Expand Down
13 changes: 8 additions & 5 deletions src/signal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use tokio_util::task::LocalPoolHandle;
use tracing::{error, warn};
use url::Url;

use crate::config::{self, Config, DeprecatedConfigKey, LoadedConfig};
use crate::config::{self, Config, DeprecatedConfigKey, DeprecatedKeys, LoadedConfig};

use self::r#impl::PresageManager;
pub use self::manager::{Attachment, ResolvedGroup, SignalManager};
Expand Down Expand Up @@ -46,11 +46,14 @@ pub async fn ensure_linked_device(
let config = config.map(
|LoadedConfig {
config,
deprecated_keys,
deprecated_keys: DeprecatedKeys { file_path, keys },
}| {
for DeprecatedConfigKey { key, message } in deprecated_keys {
warn!(key, message, "deprecated config key");
println!("deprecated config key: {key}, {message}");
if !keys.is_empty() {
println!("In '{}':", file_path.display());
for DeprecatedConfigKey { key, message } in keys {
warn!(key, message, "deprecated config key");
println!("deprecated config key: {key}, {message}");
}
}
config
},
Expand Down

0 comments on commit 826f2dc

Please sign in to comment.