From a9455eb947bce374a6b10974b4a119d255ec4061 Mon Sep 17 00:00:00 2001 From: Dino Date: Wed, 8 Oct 2025 13:38:26 +0100 Subject: [PATCH] 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 --- crates/migrator/src/migrator.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/migrator/src/migrator.rs b/crates/migrator/src/migrator.rs index 74205edd8a..a493b1efbe 100644 --- a/crates/migrator/src/migrator.rs +++ b/crates/migrator/src/migrator.rs @@ -65,7 +65,13 @@ fn migrate(text: &str, patterns: MigrationPatterns, query: &Query) -> Result Result> { + if text.is_empty() { + return Ok(None); + } + let mut current_text = text.to_string(); let mut result: Option = 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(