{"record":{"id":"d68d621f4016ffe5","repo":"EllanJiang/GameFramework","slug":"access-is-invalid-filesystemmanager","errorCode":null,"errorMessage":"Access is invalid.","messagePattern":"Access is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/FileSystem/FileSystemManager.cs","lineNumber":151,"sourceCode":"        /// <param name=\"access\">要创建的文件系统的访问方式。</param>\n        /// <param name=\"maxFileCount\">要创建的文件系统的最大文件数量。</param>\n        /// <param name=\"maxBlockCount\">要创建的文件系统的最大块数据数量。</param>\n        /// <returns>创建的文件系统。</returns>\n        public IFileSystem CreateFileSystem(string fullPath, FileSystemAccess access, int maxFileCount, int maxBlockCount)\n        {\n            if (m_FileSystemHelper == null)\n            {\n                throw new GameFrameworkException(\"File system helper is invalid.\");\n            }\n\n            if (string.IsNullOrEmpty(fullPath))\n            {\n                throw new GameFrameworkException(\"Full path is invalid.\");\n            }\n\n            if (access == FileSystemAccess.Unspecified)\n            {\n                throw new GameFrameworkException(\"Access is invalid.\");\n            }\n\n            if (access == FileSystemAccess.Read)\n            {\n                throw new GameFrameworkException(\"Access read is invalid.\");\n            }\n\n            fullPath = Utility.Path.GetRegularPath(fullPath);\n            if (m_FileSystems.ContainsKey(fullPath))\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"File system '{0}' is already exist.\", fullPath));\n            }\n\n            FileSystemStream fileSystemStream = m_FileSystemHelper.CreateFileSystemStream(fullPath, access, true);\n            if (fileSystemStream == null)\n            {\n                throw new GameFrameworkException(Utility.Text.Format(\"Create file system stream for '{0}' failure.\", fullPath));\n            }","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/FileSystem/FileSystemManager.cs#L133-L169","documentation":"CreateFileSystem requires an explicit FileSystemAccess mode. FileSystemAccess.Unspecified is only valid when opening/reading metadata, not for creating a new file system, so passing it throws 'Access is invalid.'","triggerScenarios":"Calling FileSystemManager.CreateFileSystem(fullPath, FileSystemAccess.Unspecified, maxFileCount, maxBlockCount).","commonSituations":"Access mode stored in an uninitialized enum field (default value is Unspecified for the first enum member), or code copied from an Open call where Unspecified was meant to infer access from an existing file.","solutions":["Pass FileSystemAccess.ReadWrite (or Write) explicitly to CreateFileSystem.","Fix the source of the access variable — ensure it is set, not default(Unspecified).","If access depends on context, resolve it to a concrete value before creating."],"exampleFix":"// before\nvar fs = fileSystemManager.CreateFileSystem(fullPath, FileSystemAccess.Unspecified, 16, 1024); // throws\n// after\nvar fs = fileSystemManager.CreateFileSystem(fullPath, FileSystemAccess.ReadWrite, 16, 1024);","handlingStrategy":"validation","validationCode":"if (access == FileSystemAccess.Unspecified)\n    access = FileSystemAccess.ReadWrite; // or reject before calling CreateFileSystem","typeGuard":"static bool IsExplicitAccess(FileSystemAccess access) => access == FileSystemAccess.Read || access == FileSystemAccess.Write || access == FileSystemAccess.ReadWrite;","tryCatchPattern":"try { fileSystemManager.CreateFileSystem(fullPath, access, maxFileCount, maxBlockCount); }\ncatch (GameFrameworkException ex) when (ex.Message == \"Access is invalid.\") { /* substitute a concrete access mode and retry */ }","preventionTips":["Never persist or pass through FileSystemAccess.Unspecified; resolve it to Read/Write/ReadWrite as early as possible.","Initialize access-mode fields with an explicit value, not the enum default.","Restrict CreateFileSystem call sites to a wrapper that requires an explicit mode parameter."],"tags":["filesystem","enum","validation","creation"],"backgroundTag":"invalid-enum-value","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"}