{"record":{"id":"1d0423ba539c0d1f","repo":"EllanJiang/GameFramework","slug":"name-is-invalid-filesystem","errorCode":null,"errorMessage":"Name is invalid.","messagePattern":"Name is invalid\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/FileSystem/FileSystem.cs","lineNumber":263,"sourceCode":"            m_StringDatas.Clear();\n            m_FreeStringIndexes.Clear();\n            m_FreeStringDatas.Clear();\n\n            m_BlockDataOffset = 0;\n            m_StringDataOffset = 0;\n            m_FileDataOffset = 0;\n        }\n\n        /// <summary>\n        /// 获取文件信息。\n        /// </summary>\n        /// <param name=\"name\">要获取文件信息的文件名称。</param>\n        /// <returns>获取的文件信息。</returns>\n        public FileInfo GetFileInfo(string name)\n        {\n            if (string.IsNullOrEmpty(name))\n            {\n                throw new GameFrameworkException(\"Name is invalid.\");\n            }\n\n            int blockIndex = 0;\n            if (!m_FileDatas.TryGetValue(name, out blockIndex))\n            {\n                return default(FileInfo);\n            }\n\n            BlockData blockData = m_BlockDatas[blockIndex];\n            return new FileInfo(name, GetClusterOffset(blockData.ClusterIndex), blockData.Length);\n        }\n\n        /// <summary>\n        /// 获取所有文件信息。\n        /// </summary>\n        /// <returns>获取的所有文件信息。</returns>\n        public FileInfo[] GetAllFileInfos()\n        {","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/FileSystem/FileSystem.cs#L245-L281","documentation":"GetFileInfo looks up a file entry by its exact name in the filesystem's internal dictionary and requires a non-empty name to perform the lookup. An empty or null name cannot match any entry, so it is rejected before the dictionary access.","triggerScenarios":"Calling fileSystem.GetFileInfo(null) or GetFileInfo(\"\"). Note: a valid but non-existent name does NOT throw — it returns default(FileInfo); only null/empty throws.","commonSituations":"A file name variable sourced from user input, a save slot, or a config field that was never populated; string operations that produced an empty name (e.g. Path.GetFileName on a directory-only path).","solutions":["Ensure the name passed is the exact non-empty string used when the file was added to the filesystem","Guard the caller with string.IsNullOrEmpty before calling GetFileInfo","Check where the name originates (config, user input) and validate/populate it earlier","Remember lookups are exact and case-sensitive (StringComparer.Ordinal) — verify the name matches the stored one"],"exampleFix":"// before\nvar info = fileSystem.GetFileInfo(fileName); // fileName may be \"\"\n// after\nif (string.IsNullOrEmpty(fileName)) return default(FileInfo);\nvar info = fileSystem.GetFileInfo(fileName);\nif (info.Name == null) { /* file not found handling */ }","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(name)) throw new ArgumentException(\"name is required\", nameof(name));\nvar info = fileSystem.GetFileInfo(name);","typeGuard":"bool IsValidFileName(string n) => !string.IsNullOrEmpty(n);","tryCatchPattern":"try { var info = fileSystem.GetFileInfo(name); }\ncatch (GameFrameworkException ex) when (ex.Message == \"Name is invalid.\") { Log.Error(\"GetFileInfo called with empty name — check the name source\"); }","preventionTips":["Validate the name at its source (config, user input) before filesystem calls","Remember lookups are exact and case-sensitive (ordinal) — reuse the same name constant used at AddFile time","Check default(FileInfo) return for not-found names instead of expecting an exception"],"tags":["gameframework","filesystem","argument-validation"],"backgroundTag":"missing-required-argument","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"}