{"record":{"id":"b29e300c735b3b48","repo":"FyroxEngine/Fyrox","slug":"registering-empty-path","errorCode":null,"errorMessage":"Registering empty path.","messagePattern":"Registering empty path\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"fyrox-resource/src/registry.rs","lineNumber":179,"sourceCode":"    pub fn remove_metadata(&mut self, path: impl AsRef<Path>) -> Result<(), FileError> {\n        if self.unregister_path(&path).is_some() {\n            let metadata_path = append_extension(path.as_ref(), ResourceMetadata::EXTENSION);\n\n            self.registry.io.delete_file_sync(&metadata_path)?;\n\n            Ok(())\n        } else {\n            Err(FileError::Custom(format!(\n                \"The {:?} resource is not registered in the registry!\",\n                path.as_ref()\n            )))\n        }\n    }\n\n    /// Registers a new pair `UUID -> Path`, and returns the former path for this UUID.\n    pub fn register(&mut self, uuid: Uuid, path: PathBuf) -> RegistryUpdate<Option<PathBuf>> {\n        if path.as_os_str().is_empty() {\n            panic!(\"Registering empty path.\");\n        }\n        use std::collections::btree_map::Entry;\n        match self.registry.paths.entry(uuid) {\n            Entry::Vacant(entry) => {\n                info!(\"Registered: {uuid} -> {path:?}\");\n                self.changed = true;\n                entry.insert(path);\n                RegistryUpdate {\n                    changed: true,\n                    value: None,\n                }\n            }\n            Entry::Occupied(mut entry) => {\n                let changed = entry.get() != &path;\n                if changed {\n                    info!(\"Registry update: {uuid} -> {path:?}\");\n                    self.changed = true;\n                }","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/FyroxEngine/Fyrox/blob/76c91aad8eca488ce527b1af707be8b3b24ad72d/fyrox-resource/src/registry.rs#L161-L197","documentation":"ResourceRegistry (the persistent UUID->Path mapping backing the resource registry file) refuses to register an empty path, because an empty path cannot be resolved or reloaded later. register() panics when path.as_os_str().is_empty().","triggerScenarios":"Calling registry.register(uuid, PathBuf::new()) directly, or read_metadata/write_metadata-driven flows that derive paths from resources whose path was never set (e.g. in-memory or programmatically created resources with empty path fields) and then save the registry.","commonSituations":"Saving a registry that includes resources built from memory (ResourceKind::Embedded / in-memory) that have no file path; stripping a filename incorrectly (Path::new(\"file.png\").parent() yields \"\"); default-constructed PathBuf passed through.","solutions":["Skip empty paths before calling register: only register resources whose path() is Some and non-empty.","Assign a real path to the resource before registry save (or mark it embedded/in-memory so it is not persisted).","Fix path derivation code that produces PathBuf::new() (e.g. .parent() on a bare filename).","When building from memory, use build_from_memory-style APIs that do not require registry paths."],"exampleFix":"// before\nregistry.register(uuid, resource.path().unwrap_or_default()); // may be empty\n// after\nif let Some(path) = resource.path() {\n    if !path.as_os_str().is_empty() {\n        registry.register(uuid, path);\n    }\n}","handlingStrategy":"validation","validationCode":"fn registerable(r: &UntypedResource) -> bool {\n    r.path().map_or(false, |p| !p.as_os_str().is_empty())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Filter out in-memory/embedded resources before registry save.","Never build paths with .parent() on bare filenames without handling \"\".","Default resource path fields to a placeholder, never PathBuf::new(), when a path is mandatory.","Audit resources list before write_metadata for empty paths."],"tags":["rust","panic","path","registry","serialization"],"backgroundTag":"empty-required-field","analyzedSha":"76c91aad8eca488ce527b1af707be8b3b24ad72d","analyzedAt":"2026-09-10T16:04:01.633Z","contentChangedAt":"2026-09-10T16:04:01.633Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}