FyroxEngine/Fyrox · error · std::io::Error

Invalid path

Error message

Invalid path: {}

What it means

make_relative_path converts an absolute path to one relative to the resource/working directory. It strips the file name before canonicalizing the parent directory (canonicalization requires the path to exist). If the input path has no file-name component (e.g. a bare directory root like "/" or ".." segments only), it cannot proceed and returns an InvalidData io::Error.

Solutions

  1. Pass a full path that includes the file name of an existing file
  2. Normalize/canonicalize the path (strip trailing separators) before calling
  3. Check path.file_name().is_some() before invoking and surface a friendly error

Example fix

// before
engine.resource_manager.resource_path_abs("/");

// after
let abs = engine.resource_manager.resource_path_abs("data/scene.fbx")?;
Defensive patterns

Strategy: validation

Validate before calling

fn has_file_name(p: &Path) -> bool { p.file_name().is_some() }

Type guard

fn is_valid_resource_path(p: &Path) -> bool { !p.as_os_str().is_empty() && p.file_name().is_some() }

Try / catch

match make_relative_path(&p) { Ok(rel) => rel, Err(e) => eprintln!("bad path {}: {e}", p.display()) }

Prevention

When it happens

Trigger: Passing a path with no file name ("/", "C:\\", ".\\sub\\" style paths ending in a separator, or ".") other than the literal "." shortcut, to make_relative_path; called from relative_path, open, refresh, save_scene, load_scene, LightmapperSettings.

Common situations: Users pointing engine settings at a directory instead of a file; loading scenes via paths built by string concatenation that leave a trailing separator; drive/root paths on Windows or Unix.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of FyroxEngine/Fyrox@76c91aad8e (2026-09-10). Data as JSON: /api/errors/4f04878b19529b63. Report an issue: GitHub.

Appendix: source

Thrown at fyrox-core/src/lib.rs:313

#[inline]
pub fn hash_combine(lhs: u64, rhs: u64) -> u64 {
    lhs ^ (rhs
        .wrapping_add(0x9e3779b9)
        .wrapping_add(lhs << 6)
        .wrapping_add(lhs >> 2))
}

/// Strip working directory from file name. The function may fail for one main reason -
/// input path is not valid, does not exist, or there is some other issues with it.
/// The last component of the path is permitted to not exist, so long as the rest of the path exists.
pub fn make_relative_path<P: AsRef<Path>>(path: P) -> Result<PathBuf, std::io::Error> {
    let path = path.as_ref();
    if path.as_os_str() == "." {
        return Ok(path.to_path_buf());
    }
    // Canonicalization requires the full path to exist, so remove the file name before
    // calling canonicalize.
    let file_name = path.file_name().ok_or(std::io::Error::new(
        std::io::ErrorKind::InvalidData,
        format!("Invalid path: {}", path.display()),
    ))?;
    let dir = path.parent();
    let dir = if let Some(dir) = dir {
        if dir.as_os_str().is_empty() {
            Path::new(".")
        } else {
            dir
        }
    } else {
        Path::new(".")
    };

    let cwd = std::env::current_dir()?;

    // Try without canonicalization first to preserve symlinks.
    let non_canon_dir = if dir.is_absolute() {

View on GitHub (pinned to 76c91aad8e)