{"record":{"id":"0b0f8dce7d86f573","repo":"EllanJiang/GameFramework","slug":"old-name-is-invalid","errorCode":null,"errorMessage":"Old name is invalid.","messagePattern":"Old name is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/FileSystem/FileSystem.cs","lineNumber":1018,"sourceCode":"            }\n        }\n\n        /// <summary>\n        /// 重命名指定文件。\n        /// </summary>\n        /// <param name=\"oldName\">要重命名的文件名称。</param>\n        /// <param name=\"newName\">重命名后的文件名称。</param>\n        /// <returns>是否重命名指定文件成功。</returns>\n        public bool RenameFile(string oldName, string newName)\n        {\n            if (m_Access != FileSystemAccess.Write && m_Access != FileSystemAccess.ReadWrite)\n            {\n                throw new GameFrameworkException(\"File system is not writable.\");\n            }\n\n            if (string.IsNullOrEmpty(oldName))\n            {\n                throw new GameFrameworkException(\"Old name is invalid.\");\n            }\n\n            if (string.IsNullOrEmpty(newName))\n            {\n                throw new GameFrameworkException(\"New name is invalid.\");\n            }\n\n            if (newName.Length > byte.MaxValue)\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"New name '{0}' is too long.\", newName));\n            }\n\n            if (oldName == newName)\n            {\n                return true;\n            }\n\n            if (m_FileDatas.ContainsKey(newName))","sourceCodeStart":1000,"sourceCodeEnd":1036,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/FileSystem/FileSystem.cs#L1000-L1036","documentation":"FileSystem.RenameFile(string oldName, string newName) throws this when oldName is null or empty. oldName identifies the stored file to rename; without it the library cannot locate a target and rejects the call immediately.","triggerScenarios":"Calling RenameFile(null, newName) or RenameFile(\"\", newName), usually from an unassigned variable, an empty selection in a tool UI, or a lookup that defaulted to empty.","commonSituations":"Editor tool passes the currently selected file's name but nothing is selected; a filename parsed from a manifest line was empty because of a trailing separator or format change.","solutions":["Pass a non-null, non-empty oldName to RenameFile.","Validate with string.IsNullOrWhiteSpace before calling, and skip or warn when empty.","Ensure the file actually exists (GetFileInfo(name).IsValid) before renaming to avoid confusion with other failure modes."],"exampleFix":"// before\nfileSystem.RenameFile(selectedName, newName);\n// after\nif (!string.IsNullOrWhiteSpace(selectedName))\n{\n    fileSystem.RenameFile(selectedName, newName);\n}","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(oldName)) return false;\nif (!fs.GetFileInfo(oldName).IsValid) return false; // nothing to rename","typeGuard":null,"tryCatchPattern":"try { fs.RenameFile(oldName, newName); }\ncatch (GameFrameworkException ex) when (ex.Message == \"Old name is invalid.\") { /* log empty source name */ }","preventionTips":["Guard tool/UI code paths where selection can be empty.","Validate manifest-derived names for blank entries before batch renames.","Check file existence with GetFileInfo before renaming to avoid masking other issues."],"tags":["gameframework","filesystem","argument-validation","empty-string"],"backgroundTag":"empty-required-field","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}