FuelLabs/sway · error
Cannot get parent dir of {:?}
Error message
Cannot get parent dir of {:?} What it means
In WorkspaceManifestFile::from_file the Forc.toml path is canonicalized and then .parent() is taken; this error fires when parent() returns None, which for a canonicalized absolute path happens only when the file sits at the filesystem root ('/'). It is an internal sanity guard rather than a routine user error.
Source
Thrown at forc-pkg/src/manifest/mod.rs:1032
Ok(member_pkg_manifests)
}
/// Check if given path corresponds to any workspace member's path
pub fn is_member_path(&self, path: &Path) -> Result<bool> {
Ok(self.member_paths()?.any(|member_path| member_path == path))
}
}
impl GenericManifestFile for WorkspaceManifestFile {
/// Given a path to a `Forc.toml`, read it and construct a `PackageManifest`
///
/// This also `validate`s the manifest, returning an `Err` in the case that given members are
/// not present in the manifest dir.
fn from_file<P: AsRef<Path>>(path: P) -> Result<Self> {
let path = path.as_ref().canonicalize()?;
let parent = path
.parent()
.ok_or_else(|| anyhow!("Cannot get parent dir of {:?}", path))?;
let manifest = WorkspaceManifest::from_file(&path)?;
manifest.validate(parent)?;
Ok(Self { manifest, path })
}
/// Read the manifest from the `Forc.toml` in the directory specified by the given `path` or
/// any of its parent directories.
///
/// This is short for `PackageManifest::from_file`, but takes care of constructing the path to the
/// file.
fn from_dir<P: AsRef<Path>>(manifest_dir: P) -> Result<Self> {
let manifest_dir = manifest_dir.as_ref();
let dir = find_parent_manifest_dir_with_check(manifest_dir, |possible_manifest_dir| {
// Check if the found manifest file is a workspace manifest file or a standalone
// package manifest file.
let possible_path = possible_manifest_dir.join(constants::MANIFEST_FILE_NAME);
// We should not continue to search if the given manifest is a workspace manifest with
// some issues.View on GitHub (pinned to 47e5e902fa)
Solutions
- Print/inspect the path passed to from_file and make sure it points to a Forc.toml inside a real project directory.
- Guard with path.parent().is_some() (after canonicalize) before calling the API.
- Fix the path construction (use push instead of join with absolute components).
Example fix
// before
let ws = WorkspaceManifestFile::from_file(PathBuf::from("/").join("Forc.toml"))?;
// after
let dir = std::env::current_dir()?.join("project");
assert!(dir.parent().is_some(), "manifest must live inside a directory");
let ws = WorkspaceManifestFile::from_file(dir.join("Forc.toml"))?; Defensive patterns
Strategy: type-guard
Validate before calling
let canon = std::fs::canonicalize(&manifest_path)?;
if canon.parent().map(|p| !p.as_os_str().is_empty()).unwrap_or(false) {
let ws = WorkspaceManifestFile::from_file(&manifest_path)?;
} Type guard
fn manifest_path_has_parent(path: &Path) -> bool {
path.canonicalize()
.ok()
.and_then(|p| p.parent().map(|x| !x.as_os_str().is_empty()))
.unwrap_or(false)
} Prevention
- Pass absolute, non-root paths to manifest APIs.
- Build paths with PathBuf::push so an absolute component cannot overwrite the base.
- Never place Forc.toml at the filesystem root.
When it happens
Trigger: WorkspaceManifestFile::from_file(path) where path canonicalizes to '/' - i.e. a Forc.toml literally placed at the filesystem root, or a path built by PathBuf::join where an absolute argument overwrote the base.
Common situations: Script builds '/' by joining an empty prefix with an absolute path; a Docker/CI step mounting a manifest at the root; otherwise essentially never seen.
Related errors
- failed to write toml file: {}
- graph contains no project node
- graph contains more than one project node
- failed to construct path for dependency {:?}: {}
- cannot find dependency in the workspace
AI-assisted analysis of FuelLabs/sway@47e5e902fa (2026-08-16).
Data as JSON: /api/errors/a5ef11ce124a1baf.
Report an issue: GitHub.