{"record":{"id":"25bc919bff4e0c5d","repo":"stride3d/stride","slug":"the-value-must-be-an-index-when-type-is-elementtype-index","errorCode":null,"errorMessage":"The value must be an Index when type is ElementType.Index.","messagePattern":"The value must be an Index when type is ElementType\\.Index\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Quantum/GraphNodePath.cs","lineNumber":451,"sourceCode":"    }\n\n    private void PushElement(object? elementValue, ElementType type)\n    {\n        switch (type)\n        {\n            case ElementType.Member:\n                if (elementValue is not string name)\n                    throw new ArgumentException(\"The value must be a non-null string when type is ElementType.Member.\");\n                path.Add(NodePathElement.CreateMember(name));\n                break;\n            case ElementType.Target:\n                if (elementValue != null)\n                    throw new ArgumentException(\"The value must be null when type is ElementType.Target.\");\n                path.Add(NodePathElement.CreateTarget());\n                break;\n            case ElementType.Index:\n                if (!(elementValue is NodeIndex))\n                    throw new ArgumentException(\"The value must be an Index when type is ElementType.Index.\");\n                path.Add(NodePathElement.CreateIndex((NodeIndex)elementValue));\n                break;\n            default:\n                throw new ArgumentOutOfRangeException(nameof(type));\n        }\n    }\n}\n","sourceCodeStart":433,"sourceCodeEnd":459,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Quantum/GraphNodePath.cs#L433-L459","documentation":"GraphNodePath.PushElement throws ArgumentException when ElementType.Index is requested but the value is not a NodeIndex. Index segments must be Quantum NodeIndex instances so they can represent both list indices and dictionary keys uniformly.","triggerScenarios":"Calling Push/PushIndex with a raw int, string key, or other type instead of a NodeIndex when pushing an ElementType.Index segment.","commonSituations":"Passing plain integers from UI code into path builders; forgetting to wrap dictionary keys in NodeIndex.New(key); copying path code that used ints.","solutions":["Wrap the index/key in NodeIndex before pushing (NodeIndex.New(value))","Use the typed PushIndex(NodeIndex) helper","Convert int indices via NodeIndex.New(i) and dictionary keys likewise","Catch ArgumentException and validate the element type in generic path builders"],"exampleFix":"// before\npath.Push(3, ElementType.Index);\n// after\npath.PushIndex(NodeIndex.New(3));","handlingStrategy":"type-guard","validationCode":"if (elementValue is not NodeIndex) throw new ArgumentException(\"Index path element must be a NodeIndex\");","typeGuard":"bool IsIndexElement(object? v) => v is NodeIndex;","tryCatchPattern":"try { path.Push(value, ElementType.Index); } catch (ArgumentException ex) { logger.LogError(ex, \"Invalid index path element\"); }","preventionTips":["Always wrap indices/keys in NodeIndex.New(...) before pushing","Use PushIndex(NodeIndex) instead of the generic overload","Convert raw ints/keys at the boundary of path-building code"],"tags":["path","argument","index"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}