FuelLabs/sway · error · anyhow::Error

invalid folder name

Error message

invalid folder name

What it means

While scanning the local git checkouts directory to find offline candidates, forc converts each directory name to a String. On systems with non-UTF-8 filenames, into_string() fails and this generic 'invalid folder name' error aborts the whole scan.

Source

Thrown at forc-pkg/src/source/git/mod.rs:667

            }
        }
        Ok(())
    })?;
    Ok(found_local_repo)
}

/// Search local checkouts directory and apply the given function. This is used for iterating over
/// possible options of a given package.
fn with_search_checkouts<F>(checkouts_dir: PathBuf, package_name: &str, mut f: F) -> Result<()>
where
    F: FnMut(SourceIndex, PathBuf) -> Result<()>,
{
    for entry in fs::read_dir(checkouts_dir)? {
        let entry = entry?;
        let folder_name = entry
            .file_name()
            .into_string()
            .map_err(|_| anyhow!("invalid folder name"))?;
        if folder_name.starts_with(package_name) {
            // Search if the dir we are looking starts with the name of our package
            for repo_dir in fs::read_dir(entry.path())? {
                // Iterate over all dirs inside the `name-***` directory and try to open repo from
                // each dirs inside this one
                let repo_dir = repo_dir
                    .map_err(|e| anyhow!("Cannot find local repo at checkouts dir {}", e))?;
                if repo_dir.file_type()?.is_dir() {
                    // Get the path of the current repo
                    let repo_dir_path = repo_dir.path();
                    // Get the index file from the found path
                    if let Ok(index_file) = fs::read_to_string(repo_dir_path.join(".forc_index")) {
                        let index = serde_json::from_str(&index_file)?;
                        f(index, repo_dir_path)?;
                    }
                }
            }
        }

View on GitHub (pinned to 47e5e902fa)

Solutions

  1. List the checkouts dir and remove/rename the offending non-UTF-8 entries (inspect with `ls -b` to reveal escapes)
  2. If the failing entry is unclear, temporarily move subdirectories aside until the scan passes
  3. Avoid tools that create non-UTF-8 paths inside the forc cache

Example fix

# remove non-ASCII/non-UTF-8 entries in the checkouts dir (bash)
find "$HOME/.forc/git/checkouts" -mindepth 1 -maxdepth 1 \
  -exec bash -c 'p="$1"; case "${p##*/}" in *[![:print:]]*) rm -rf "$p";; esac' _ {} \;
Defensive patterns

Strategy: validation

Validate before calling

fn checkouts_are_utf8_clean(checkouts: &Path) -> anyhow::Result<()> {
    for entry in std::fs::read_dir(checkouts)? {
        let entry = entry?;
        if entry.file_name().into_string().is_err() {
            anyhow::bail!("non-UTF-8 cache entry: {:#?}", entry.path());
        }
    }
    Ok(())
}

Prevention

When it happens

Trigger: Any file or directory under ~/.forc/git/checkouts whose name is not valid UTF-8 - created by misbehaving tooling, odd archive extraction, or manual filesystem operations.

Common situations: Machines where some tool created directory names with invalid byte sequences; restoring caches from archives with exotic names.

Related errors


AI-assisted analysis of FuelLabs/sway@47e5e902fa (2026-08-16). Data as JSON: /api/errors/2382ba27aa636aa1. Report an issue: GitHub.