{"record":{"id":"38c74d5a201455b4","repo":"EllanJiang/GameFramework","slug":"directory-name-is-invalid","errorCode":null,"errorMessage":"Directory name is invalid.","messagePattern":"Directory name is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Utility/Utility.Path.cs","lineNumber":59,"sourceCode":"                string regularPath = GetRegularPath(path);\n                if (regularPath == null)\n                {\n                    return null;\n                }\n\n                return regularPath.Contains(\"://\") ? regularPath : (\"file:///\" + regularPath).Replace(\"file:////\", \"file:///\");\n            }\n\n            /// <summary>\n            /// 移除空文件夹。\n            /// </summary>\n            /// <param name=\"directoryName\">要处理的文件夹名称。</param>\n            /// <returns>是否移除空文件夹成功。</returns>\n            public static bool RemoveEmptyDirectory(string directoryName)\n            {\n                if (string.IsNullOrEmpty(directoryName))\n                {\n                    throw new GameFrameworkException(\"Directory name is invalid.\");\n                }\n\n                try\n                {\n                    if (!Directory.Exists(directoryName))\n                    {\n                        return false;\n                    }\n\n                    // 不使用 SearchOption.AllDirectories，以便于在可能产生异常的环境下删除尽可能多的目录\n                    string[] subDirectoryNames = Directory.GetDirectories(directoryName, \"*\");\n                    int subDirectoryCount = subDirectoryNames.Length;\n                    foreach (string subDirectoryName in subDirectoryNames)\n                    {\n                        if (RemoveEmptyDirectory(subDirectoryName))\n                        {\n                            subDirectoryCount--;\n                        }","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Utility/Utility.Path.cs#L41-L77","documentation":"Utility.Path.RemoveEmptyDirectory throws when the directoryName argument is null or empty. A null/empty path can never name a directory, and Directory operations on it would fail ambiguously, so the library fails fast with GameFrameworkException. Note the method throws rather than returning false for this case.","triggerScenarios":"Calling Utility.Path.RemoveEmptyDirectory(null) or RemoveEmptyDirectory(\"\") — e.g. a configured directory name that failed to load from settings, or a joined path that came out empty.","commonSituations":"Config files where a cleanup-directory key is missing; Path.Combine results that collapsed to empty; iterating a list of directories where one entry was never initialized.","solutions":["Pass a valid, non-empty directory path; check string.IsNullOrEmpty before calling.","Fix the config/loading code that produced the empty directory name.","If the directory may legitimately be absent, check Directory.Exists first and skip the call."],"exampleFix":"// before\nstring dir = settings.GetValue(\"CacheDir\"); // may be null\nUtility.Path.RemoveEmptyDirectory(dir);\n// after\nstring dir = settings.GetValue(\"CacheDir\");\nif (!string.IsNullOrEmpty(dir) && Directory.Exists(dir))\n    Utility.Path.RemoveEmptyDirectory(dir);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(directoryName))\n    throw new ArgumentException(\"Directory name must be non-empty\", nameof(directoryName));\nbool ok = Utility.Path.RemoveEmptyDirectory(directoryName);","typeGuard":"bool IsValidDirectory(string path) => !string.IsNullOrEmpty(path);","tryCatchPattern":"try\n{\n    Utility.Path.RemoveEmptyDirectory(dir);\n}\ncatch (GameFrameworkException ex) when (ex.Message == \"Directory name is invalid.\")\n{\n    // config missing; log and use default directory\n}","preventionTips":["Validate directory-name config values at startup, before cleanup jobs run.","Use Path.Combine and check the result is non-empty before use.","Prefer explicit fallback default paths over uninitialized settings."],"tags":["path","argument-validation","gameframework"],"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"}