{"record":{"id":"d57229ee468b2c2b","repo":"Unity-Technologies/UnityCsReference","slug":"unhandled-enum-dropposition","errorCode":null,"errorMessage":"Unhandled enum {dropPosition}","messagePattern":"Unhandled enum (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GUI/TreeView/AssetOrGameObjectTreeViewDragging.cs","lineNumber":302,"sourceCode":"                if (go == null)\n                    throw new InvalidOperationException(\"Unexpected UnityEngine.Object type in Hierarchy \" + obj.GetType());\n\n                switch (dropPosition)\n                {\n                    case DropPosition.Upon:\n                        return go.transform;\n\n                    case DropPosition.Below:\n                    case DropPosition.Above:\n                        if (go.transform.parent == null)\n                        {\n                            var subSceneInfo = SubSceneGUI.GetSubSceneInfo(go.scene);\n                            if (subSceneInfo.isValid)\n                                return subSceneInfo.transform;\n                        }\n                        return go.transform.parent;\n                    default:\n                        throw new InvalidOperationException(\"Unhandled enum \" + dropPosition);\n                }\n            }\n            else\n            {\n                // Find transform parent from Scene\n                var scene = EditorSceneManager.GetSceneByHandle(SceneHandle.From(gameObjectOrSceneInstanceID));\n                var subSceneInfo = SubSceneGUI.GetSubSceneInfo(scene);\n                if (subSceneInfo.isValid)\n                    return subSceneInfo.transform;\n                return null; // root scene has no transform parent\n            }\n        }\n\n        static bool IsDropTargetUserModifiable(GameObjectTreeViewItem targetItem, DropPosition dropPos)\n        {\n            if (targetItem.isSceneHeader && !targetItem.scene.isLoaded)\n                return false;\n","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TreeView/AssetOrGameObjectTreeViewDragging.cs#L284-L320","documentation":"Thrown by the DropPosition switch inside GetTransformParentForDrop when the dropPosition enum value is not Upon, Below, or Above. This default branch guards against an unhandled enum case so the parent resolution never silently returns undefined behavior.","triggerScenarios":"Passing a DropPosition value outside the handled set (e.g. a new enum member, an invalid cast, or default(DropPosition) when '0' is unmapped).","commonSituations":"Extending DropPosition with a new mode without updating this switch; deserialization producing an out-of-range value.","solutions":["Map the dropPosition to one of Upon/Below/Above before calling the helper.","If a new DropPosition member was added, implement its transform-parent logic here.","Reject the drag with DragAndDropVisualMode.None for unrecognized positions instead of calling through."],"exampleFix":"// before\nvar p = GetTransformParentForDrop(id, dropPosition);\n\n// after\nDropPosition pos = (dropPosition == DropPosition.Upon || dropPosition == DropPosition.Below || dropPosition == DropPosition.Above)\n    ? dropPosition\n    : DropPosition.Below;\nvar p = GetTransformParentForDrop(id, pos);","handlingStrategy":"validation","validationCode":"bool validPos = dropPosition == DropPosition.Upon || dropPosition == DropPosition.Below || dropPosition == DropPosition.Above;","typeGuard":"static bool IsHandledPosition(DropPosition p) => p == DropPosition.Upon || p == DropPosition.Below || p == DropPosition.Above;","tryCatchPattern":null,"preventionTips":["When extending DropPosition, update every switch over it.","Reject drags with unsupported positions at the DragAndDrop layer.","Map deserialized positions to a known value before use."],"tags":["unity-editor","hierarchy","enum","drag-drop"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}