{"record":{"id":"0409723e9c9af1cd","repo":"babalae/better-genshin-impact","slug":"string-join-pathparts-take-i-1","errorCode":null,"errorMessage":"路径中间部分不是目录: {string.Join(\"/\", pathParts.Take(i + 1))}","messagePattern":"路径中间部分不是目录: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Core/Script/ScriptRepoUpdater.cs","lineNumber":1609,"sourceCode":"\n            for (int i = 0; i < pathParts.Length; i++)\n            {\n                entry = currentTree[pathParts[i]];\n                if (entry == null)\n                {\n                    // 调试信息：列出当前树中的所有条目\n                    // var availableEntries = string.Join(\", \", currentTree.Select(e => e.Name));\n                    // _logger.LogError($\"在路径 '{string.Join(\"/\", pathParts.Take(i))}' 中未找到 '{pathParts[i]}'\");\n                    // _logger.LogError($\"可用的条目: {availableEntries}\");\n                    // throw new Exception($\"仓库中不存在路径: {sourcePath}\");\n                    return;\n                }\n\n                if (i < pathParts.Length - 1)\n                {\n                    if (entry.TargetType != TreeEntryTargetType.Tree)\n                    {\n                        throw new Exception($\"路径中间部分不是目录: {string.Join(\"/\", pathParts.Take(i + 1))}\");\n                    }\n                    currentTree = (Tree)entry.Target;\n                }\n            }\n\n            // 检出文件或目录\n            if (entry == null)\n            {\n                // throw new Exception($\"未找到路径: {sourcePath}\");\n                return;\n            }\n\n            if (entry.TargetType == TreeEntryTargetType.Blob)\n            {\n                // 检出单个文件\n                var blob = (Blob)entry.Target;\n\n                // 确保目标目录存在","sourceCodeStart":1591,"sourceCodeEnd":1627,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Core/Script/ScriptRepoUpdater.cs#L1591-L1627","documentation":"Thrown while walking a multi-segment sourcePath through the repo tree in CheckoutPath: an intermediate path segment resolved to an entry that is NOT a Tree (it's a Blob or GitLink). You cannot descend into a file as if it were a directory, so traversal aborts.","triggerScenarios":"sourcePath like 'repo/folder/file.txt' where 'folder' is a file (Blob), not a directory. currentTree[segment] returns a Blob, then the code tries to descend (entry.Target as Tree) and rejects it because TargetType != Tree.","commonSituations":"A script manifest declares a path where a file occupies an intermediate segment that should be a directory (manifest typo); upstream renamed a file to a folder or vice versa; case-sensitivity mismatch where the directory exists with different casing on a case-sensitive server and the lookup resolves to a sibling file.","solutions":["Validate the sourcePath against the manifest/repo layout before checkout; log the full path and the offending segment.","Make the error message include the actual TargetType so devs see whether it hit a Blob or a GitLink.","If case-insensitivity is the cause, normalize segment casing against the tree entries before lookup.","Treat this as a manifest-authoring error and surface it to the script author with the exact conflicting segment."],"exampleFix":"// before\nif (entry.TargetType != TreeEntryTargetType.Tree)\n    throw new Exception($\"路径中间部分不是目录: {string.Join(\"/\", pathParts.Take(i + 1))}\");\n\n// after (include actual type)\nif (entry.TargetType != TreeEntryTargetType.Tree)\n    throw new InvalidOperationException(\n        $\"路径中间部分不是目录: {string.Join(\"/\", pathParts.Take(i + 1))} 实际类型={entry.TargetType}，请检查 sourcePath={sourcePath}\");","handlingStrategy":"validation","validationCode":"// Walk the tree validating each intermediate segment is a Tree\nfor (int i = 0; i < pathParts.Length - 1; i++)\n{\n    if (currentTree[pathParts[i]] is not { TargetType: TreeEntryTargetType.Tree } t)\n        throw new InvalidOperationException($\"中间段不是目录: {pathParts[i]}\");\n    currentTree = (Tree)t.Target;\n}","typeGuard":"static bool IsTreeSegment(Tree tree, string name) =>\n    tree[name] is { TargetType: TreeEntryTargetType.Tree };","tryCatchPattern":"catch (Exception ex) when (ex.Message.Contains(\"不是目录\"))\n{\n    _logger.LogError(\"manifest 路径冲突: {Msg}; sourcePath={Path}\", ex.Message, sourcePath);\n    throw;\n}","preventionTips":["Validate manifest paths against the repo tree at load time.","Treat this as an authoring error surfaced to the script author.","Include the actual TargetType in the message."],"tags":["git","libgit2sharp","tree-walk","path","manifest"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}