migrator: Avoid attempting to migrate empty content (#39771)

This commit fixes an issue where opening zed using `--user-data-dir`
with an empty directory would cause the first run to display a "Failed
to migrate settings" error.

This was caused by the migrator attempting to migrate an empty string,
so if that's the case, we'll simply return `Ok(None)` and avoid
attempting to migrate anything at all.

Relates to #39400

Release Notes:

- N/A

Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
This commit is contained in:
Dino
2025-10-08 13:38:26 +01:00
committed by GitHub
co-authored by Smit Barmase
parent db3c186af0
commit a9455eb947
+11
View File
@@ -65,7 +65,13 @@ fn migrate(text: &str, patterns: MigrationPatterns, query: &Query) -> Result<Opt
}
}
/// Runs the provided migrations on the given text.
/// Will automatically return `Ok(None)` if there's no content to migrate.
fn run_migrations(text: &str, migrations: &[MigrationType]) -> Result<Option<String>> {
if text.is_empty() {
return Ok(None);
}
let mut current_text = text.to_string();
let mut result: Option<String> = None;
for migration in migrations.iter() {
@@ -371,6 +377,11 @@ mod tests {
assert_migrated_correctly(migrated, output);
}
#[test]
fn test_empty_content() {
assert_migrate_settings("", None)
}
#[test]
fn test_replace_array_with_single_string() {
assert_migrate_keymap(