{"record":{"id":"de7e91665ddd4c81","repo":"Hmbown/CodeWhale","slug":"must-be-a-regular-file","errorCode":null,"errorMessage":"must be a regular file","messagePattern":"must be a regular file","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/runtime_threads.rs","lineNumber":13871,"sourceCode":"\n    let metadata = file.metadata()?;\n    let safe = metadata.is_file() && metadata.file_attributes() & FILE_ATTRIBUTE_REPARSE_POINT == 0;\n    anyhow::ensure!(safe, \"not a regular non-reparse file\");\n    let mut info = BY_HANDLE_FILE_INFORMATION::default();\n    // SAFETY: the handle and writable output remain valid for the call.\n    if unsafe { GetFileInformationByHandle(file.as_raw_handle(), &mut info) } == 0 {\n        return Err(std::io::Error::last_os_error()).context(\"Inspect Runtime store file identity\");\n    }\n    anyhow::ensure!(info.nNumberOfLinks == 1, \"has multiple filesystem links\");\n    Ok((\n        u64::from(info.dwVolumeSerialNumber),\n        (u64::from(info.nFileIndexHigh) << 32) | u64::from(info.nFileIndexLow),\n    ))\n}\n\n#[cfg(all(not(unix), not(windows)))]\nfn runtime_store_file_identity(file: &File) -> Result<(u64, u64)> {\n    anyhow::ensure!(file.metadata()?.is_file(), \"must be a regular file\");\n    Ok((0, 0))\n}\n\nfn validate_same_runtime_store_file_handles(\n    first: &File,\n    second: &File,\n    path: &Path,\n) -> Result<()> {\n    let first = runtime_store_file_identity(first)?;\n    let second = runtime_store_file_identity(second)?;\n    anyhow::ensure!(\n        first == second,\n        \"Runtime event file changed: {}\",\n        path.display()\n    );\n    Ok(())\n}\n","sourceCodeStart":13853,"sourceCodeEnd":13889,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/runtime_threads.rs#L13853-L13889","documentation":"On platforms that are neither Unix nor Windows, `runtime_store_file_identity` cannot obtain a (dev, ino) identity, so it degrades to returning (0, 0) but still requires the handle to reference a regular file via metadata.is_file(). If the handle points at a directory, FIFO, device, or other non-regular filesystem object, this error is thrown.","triggerScenarios":"Running the runtime store identity check on an unsupported platform (e.g. wasm, other OS) with a `File` whose metadata reports is_file() == false — the configured path was a directory or special file.","commonSituations":"Porting the TUI to a less common OS where the store path misconfiguration (directory instead of file) surfaces through this platform-neutral branch.","solutions":["Ensure the configured store path is a regular file, not a directory or special file: check with file metadata before opening","Fix the runtime store configuration to point at the actual store file","Note that on this platform identity is degraded to (0, 0); same-file detection via this function will treat all files as identical"],"exampleFix":"// before: store path points at a directory\nlet f = File::open(\"/var/lib/codewhale-store/\")?;\nlet id = runtime_store_file_identity(&f)?;\n// after: point at the regular store file\nlet f = File::open(\"/var/lib/codewhale-store/runtime.bin\")?;\nanyhow::ensure!(f.metadata()?.is_file());\nlet id = runtime_store_file_identity(&f)?;","handlingStrategy":"validation","validationCode":"let meta = std::fs::metadata(path)?;\nanyhow::ensure!(meta.is_file(), \"{} must be a regular file\", path.display());","typeGuard":"fn is_regular(f: &File) -> bool { f.metadata().map(|m| m.is_file()).unwrap_or(false) }","tryCatchPattern":"match runtime_store_file_identity(&f) {\n    Ok(id) => id,\n    Err(e) => fallback_to_default_identity(e),\n}","preventionTips":["Verify the store path is a file, not a directory, before launch","Remember identity is (0,0) on non-Unix/Windows platforms — don't rely on same-file detection there"],"tags":["filesystem","cross-platform","file-identity"],"backgroundTag":"incompatible-source-type","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}