{"record":{"id":"f10ff78b7652d761","repo":"EllanJiang/GameFramework","slug":"file-path-is-invalid","errorCode":null,"errorMessage":"File path is invalid","messagePattern":"File path is invalid","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/FileSystem/FileSystem.cs","lineNumber":936,"sourceCode":"                m_Stream.Write(stream, length);\n            }\n\n            ProcessWriteFile(name, hasFile, oldBlockIndex, blockIndex, length);\n            m_Stream.Flush();\n            return true;\n        }\n\n        /// <summary>\n        /// 写入指定文件。\n        /// </summary>\n        /// <param name=\"name\">要写入的文件名称。</param>\n        /// <param name=\"filePath\">存储写入文件内容的文件路径。</param>\n        /// <returns>是否写入指定文件成功。</returns>\n        public bool WriteFile(string name, string filePath)\n        {\n            if (string.IsNullOrEmpty(filePath))\n            {\n                throw new GameFrameworkException(\"File path is invalid\");\n            }\n\n            if (!File.Exists(filePath))\n            {\n                return false;\n            }\n\n            using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))\n            {\n                return WriteFile(name, fileStream);\n            }\n        }\n\n        /// <summary>\n        /// 将指定文件另存为物理文件。\n        /// </summary>\n        /// <param name=\"name\">要另存为的文件名称。</param>\n        /// <param name=\"filePath\">存储写入文件内容的文件路径。</param>","sourceCodeStart":918,"sourceCodeEnd":954,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/FileSystem/FileSystem.cs#L918-L954","documentation":"FileSystem.WriteFile(string name, string filePath) throws this when filePath is null or an empty string. The method reads the content of the physical file at filePath and stores it in the virtual file system; without a path there is nothing to read.","triggerScenarios":"Calling WriteFile(name, null) or WriteFile(name, \"\"), typically because a config value, path-joining result, or env-derived variable was never set.","commonSituations":"A settings field holding the source file path is missing/empty; Path.Combine produces an empty component; a migration changed a method signature and callers pass the wrong (empty) variable.","solutions":["Pass a non-null, non-empty path to WriteFile.","Validate/resolve the path before the call (log and abort if empty).","Fix the configuration or default value that should supply the path."],"exampleFix":"// before\nfileSystem.WriteFile(name, config.SourcePath); // SourcePath may be empty\n// after\nif (!string.IsNullOrEmpty(config.SourcePath))\n{\n    fileSystem.WriteFile(name, config.SourcePath);\n}","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(filePath)) return; // or throw\nif (!File.Exists(filePath)) return false; // WriteFile returns false for missing files","typeGuard":null,"tryCatchPattern":"try { fs.WriteFile(name, filePath); }\ncatch (GameFrameworkException ex) when (ex.Message == \"File path is invalid\") { /* fix/configure path */ }","preventionTips":["Validate configuration paths at startup, before any write loop runs.","Resolve paths through one utility that rejects null/empty early.","Distinguish 'path empty' (bug) from 'file missing' (WriteFile returns false) when handling results."],"tags":["gameframework","filesystem","argument-validation","file-path"],"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-23T08:17:48.524Z"}