{"record":{"id":"954e745fe573f86a","repo":"EllanJiang/GameFramework","slug":"new-name-0-is-too-long","errorCode":null,"errorMessage":"New name '{0}' is too long.","messagePattern":"New name '(.+?)' is too long\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/FileSystem/FileSystem.cs","lineNumber":1028,"sourceCode":"        {\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;\n            if (!m_FileDatas.TryGetValue(oldName, out blockIndex))\n            {\n                return false;\n            }\n","sourceCodeStart":1010,"sourceCodeEnd":1046,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/FileSystem/FileSystem.cs#L1010-L1046","documentation":"FileSystem.RenameFile (or similar rename API) validates that the new file name length fits in a single byte, because the file system format stores the name length as a byte. If newName.Length exceeds byte.MaxValue (255), the rename cannot be recorded in the file system header, so the library throws before doing any work.","triggerScenarios":"Calling a public rename method on FileSystem (e.g. RenameFile/RenameData) with a newName whose string length is greater than 255 characters and which passes the earlier 'New name is invalid.' check (non-empty, not equal to oldName is checked after).","commonSituations":"Programmatically building names from long paths, hashes, GUIDs with prefixes, or concatenating labels/separators until the name exceeds 255 chars; copying a full path instead of a bare file name into the rename call.","solutions":["Shorten newName to 255 characters or fewer before calling the rename API.","Assert/guard newName.Length <= byte.MaxValue in calling code and surface a user-facing validation message instead of crashing.","If the desired identifier is inherently long, store the long value as file content or metadata and use a short generated name (e.g. hash) instead."],"exampleFix":"// before\nfileSystem.RenameFile(\"old.dat\", veryLongGeneratedName); // throws if > 255 chars\n// after\nif (veryLongGeneratedName.Length > byte.MaxValue)\n    veryLongGeneratedName = Utility.Text.Format(\"{0}\", Utility.Verifier.GetCRC32(...)); // or otherwise shorten\nfileSystem.RenameFile(\"old.dat\", veryLongGeneratedName);","handlingStrategy":"validation","validationCode":"if (newName == null || newName.Length == 0 || newName.Length > byte.MaxValue)\n    throw new ArgumentException(\"New name must be 1-255 characters.\", nameof(newName));","typeGuard":"static bool IsValidNewName(string newName) => !string.IsNullOrEmpty(newName) && newName.Length <= byte.MaxValue;","tryCatchPattern":"try { fileSystem.RenameFile(oldName, newName); }\ncatch (GameFrameworkException ex) when (ex.Message.StartsWith(\"New name\")) { /* surface a 'name too long' validation error to the user */ }","preventionTips":["Enforce a max-name-length constant (255) in your own naming helper used everywhere.","Never pass full paths or auto-concatenated identifiers as file system names.","Write a unit test that tries a 256-char name and asserts a friendly failure."],"tags":["filesystem","rename","validation","argument-length"],"backgroundTag":"value-out-of-range","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}