Repository: alacritty/alacritty
File: alacritty/src/migrate/mod.rs (Rust)

Code before:
    path: &Path,
    document: &mut DocumentMut,
    recursion_limit: usize,
) -> Result<(), String> {
    // Check if any imports need to be processed.
    let imports = match document
        .get("general")
        .and_then(|general| general.get("import"))
        .and_then(|import| import.as_array())
    {
        Some(array) if !array.is_empty() => array,
        _ => return Ok(()),
    };

    // Abort once recursion limit is exceeded.
    if recursion_limit == 0 {
        return Err("Exceeded maximum configuration import depth".into());
    }

    // Migrate each import.
    for import in imports.into_iter().filter_map(|item| item.as_str()) {
        let normalized_path = config::normalize_import(path, import);

        if !normalized_path.exists() {
            if options.dry_run {
                println!("Skipping migration for nonexisting path: {}", normalized_path.display());
            }
            continue;
        }

        let migration = migrate_config(options, &normalized_path, recursion_limit - 1)?;
        if options.dry_run {
            println!("{}", migration.success_message(true));
        }
    }

    Ok(())
}

/// Move a TOML value from one map to another.
fn move_value(document: &mut DocumentMut, origin: &[&str], target: &[&str]) -> Result<(), String> {
    // Find and remove the original item.
    let (mut origin_key, mut origin_item) = (None, document.as_item_mut());
    for element in origin {
        let table = match origin_item.as_table_like_mut() {
            Some(table) => table,
            None => panic!("Moving from unsupported TOML structure"),
        };

        let (key, item) = match table.get_key_value_mut(element) {
            Some((key, item)) => (key, item),

Review comment (suggestion):
```suggestion
                println!("Skipping migration for nonexistent path: {}", normalized_path.display());
```

Code after:
    path: &Path,
    document: &mut DocumentMut,
    recursion_limit: usize,
) -> Result<(), String> {
    // Check if any imports need to be processed.
    let imports = match document
        .get("general")
        .and_then(|general| general.get("import"))
        .and_then(|import| import.as_array())
    {
        Some(array) if !array.is_empty() => array,
        _ => return Ok(()),
    };

    // Abort once recursion limit is exceeded.
    if recursion_limit == 0 {
        return Err("Exceeded maximum configuration import depth".into());
    }

    // Migrate each import.
    for import in imports.into_iter().filter_map(|item| item.as_str()) {
        let normalized_path = config::normalize_import(path, import);

        if !normalized_path.exists() {
            if options.dry_run {
                println!("Skipping migration for nonexistent path: {}", normalized_path.display());
            }
            continue;
        }

        let migration = migrate_config(options, &normalized_path, recursion_limit - 1)?;
        if options.dry_run {
            println!("{}", migration.success_message(true));
        }
    }

    Ok(())
}

/// Move a TOML value from one map to another.
fn move_value(document: &mut DocumentMut, origin: &[&str], target: &[&str]) -> Result<(), String> {
    // Find and remove the original item.
    let (mut origin_key, mut origin_item) = (None, document.as_item_mut());
    for element in origin {
        let table = match origin_item.as_table_like_mut() {
            Some(table) => table,
            None => panic!("Moving from unsupported TOML structure"),
        };

        let (key, item) = match table.get_key_value_mut(element) {
            Some((key, item)) => (key, item),