{"record":{"id":"d4e707d20227cdcc","repo":"EllanJiang/GameFramework","slug":"name-is-invalid","errorCode":null,"errorMessage":"Name is invalid.","messagePattern":"Name is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/DataNode/DataNodeManager.DataNode.cs","lineNumber":159,"sourceCode":"            /// 根据索引检查是否存在子数据结点。\n            /// </summary>\n            /// <param name=\"index\">子数据结点的索引。</param>\n            /// <returns>是否存在子数据结点。</returns>\n            public bool HasChild(int index)\n            {\n                return index >= 0 && index < ChildCount;\n            }\n\n            /// <summary>\n            /// 根据名称检查是否存在子数据结点。\n            /// </summary>\n            /// <param name=\"name\">子数据结点名称。</param>\n            /// <returns>是否存在子数据结点。</returns>\n            public bool HasChild(string name)\n            {\n                if (!IsValidName(name))\n                {\n                    throw new GameFrameworkException(\"Name is invalid.\");\n                }\n\n                if (m_Childs == null)\n                {\n                    return false;\n                }\n\n                foreach (DataNode child in m_Childs)\n                {\n                    if (child.Name == name)\n                    {\n                        return true;\n                    }\n                }\n\n                return false;\n            }\n","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/DataNode/DataNodeManager.DataNode.cs#L141-L177","documentation":"DataNode.HasChild throws 'Name is invalid.' when the child name argument fails IsValidName (null/empty/illegal characters). HasChild is a boolean existence check, so rather than returning false it demands a well-formed name. This prevents silent 'child not found' results caused by malformed input.","triggerScenarios":"Calling node.HasChild(null), HasChild(\"\"), or HasChild(\"a/b\") — a name containing the path separator; passing a variable that was split from a path into an empty segment.","commonSituations":"Querying children with a full path instead of a single child name (paths belong to GetNode); an uninitialized string variable; empty entries from a Split('/') producing empty segments.","solutions":["Pass a single valid child name, not a full path — use GetNode for paths","Validate with DataNode.IsValidName(name) before calling","Trim/normalize the name and reject empty segments"],"exampleFix":"// before\nbool has = node.HasChild(childName);\n// after\nif (DataNode.IsValidName(childName))\n{\n    bool has = node.HasChild(childName);\n}","handlingStrategy":"validation","validationCode":"if (!DataNode.IsValidName(name))\n{\n    return false;\n}","typeGuard":"bool ValidChildName(string s) => !string.IsNullOrEmpty(s) && !s.Contains(\"/\");","tryCatchPattern":"try { has = node.HasChild(name); }\ncatch (GameFrameworkException) { Log.Error($\"Invalid child name '{name}'\"); has = false; }","preventionTips":["Pass direct child names to HasChild, paths to GetNode","Reject empty segments from path splits","Use constants for node names","Avoid whitespace-only names"],"tags":["datanode","gameframework","invalid-name"],"backgroundTag":"invalid-argument-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"}