{"record":{"id":"a0588f61761ad4a0","repo":"EllanJiang/GameFramework","slug":"new-name-is-invalid","errorCode":null,"errorMessage":"New name is invalid.","messagePattern":"New name is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/FileSystem/FileSystem.cs","lineNumber":1023,"sourceCode":"        /// </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))\n            {\n                return false;\n            }\n\n            int blockIndex = 0;","sourceCodeStart":1005,"sourceCodeEnd":1041,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/FileSystem/FileSystem.cs#L1005-L1041","documentation":"FileSystem.RenameFile(string oldName, string newName) throws this when newName is null or empty. The new name is what gets written into the file system's name table, so an empty replacement is rejected up front.","triggerScenarios":"Calling RenameFile(oldName, null) or RenameFile(oldName, \"\"), typically when the new name comes from an empty text field, a cancelled input dialog, or a variable that was never populated.","commonSituations":"A rename dialog returns an empty string when the user confirms without typing; scripted batch renames read the new names from a file where some lines are blank.","solutions":["Pass a non-null, non-empty newName to RenameFile.","Validate the new name (string.IsNullOrWhiteSpace) before invoking; prompt the user again if empty.","Keep newName within byte.MaxValue characters as well, since a separate length check follows immediately."],"exampleFix":"// before\nfileSystem.RenameFile(oldName, renameInput.text);\n// after\nif (!string.IsNullOrWhiteSpace(renameInput.text) && renameInput.text.Length <= byte.MaxValue)\n{\n    fileSystem.RenameFile(oldName, renameInput.text);\n}","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(newName)) return false; // or re-prompt\nif (newName.Length > byte.MaxValue) return false;","typeGuard":null,"tryCatchPattern":"try { fs.RenameFile(oldName, newName); }\ncatch (GameFrameworkException ex) when (ex.Message == \"New name is invalid.\") { /* re-prompt for a valid name */ }","preventionTips":["Require non-empty rename input in dialogs before enabling the confirm button.","Enforce the 255-character cap on new names in the UI layer.","In batch renames, skip blank target names and report them instead of calling the API."],"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"}