{"record":{"id":"90aa505613b1ebcf","repo":"EllanJiang/GameFramework","slug":"range-is-invalid","errorCode":null,"errorMessage":"Range is invalid.","messagePattern":"Range is invalid\\.","errorType":"exception","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/Base/GameFrameworkLinkedListRange.cs","lineNumber":33,"sourceCode":"    /// 游戏框架链表范围。\n    /// </summary>\n    /// <typeparam name=\"T\">指定链表范围的元素类型。</typeparam>\n    [StructLayout(LayoutKind.Auto)]\n    public struct GameFrameworkLinkedListRange<T> : IEnumerable<T>, IEnumerable\n    {\n        private readonly LinkedListNode<T> m_First;\n        private readonly LinkedListNode<T> m_Terminal;\n\n        /// <summary>\n        /// 初始化游戏框架链表范围的新实例。\n        /// </summary>\n        /// <param name=\"first\">链表范围的开始结点。</param>\n        /// <param name=\"terminal\">链表范围的终结标记结点。</param>\n        public GameFrameworkLinkedListRange(LinkedListNode<T> first, LinkedListNode<T> terminal)\n        {\n            if (first == null || terminal == null || first == terminal)\n            {\n                throw new GameFrameworkException(\"Range is invalid.\");\n            }\n\n            m_First = first;\n            m_Terminal = terminal;\n        }\n\n        /// <summary>\n        /// 获取链表范围是否有效。\n        /// </summary>\n        public bool IsValid\n        {\n            get\n            {\n                return m_First != null && m_Terminal != null && m_First != m_Terminal;\n            }\n        }\n\n        /// <summary>","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/Base/GameFrameworkLinkedListRange.cs#L15-L51","documentation":"GameFrameworkLinkedListRange<T> represents a contiguous segment of a LinkedList<T> defined by a first node and a terminal sentinel node. The constructor throws when first or terminal is null, or when both reference the same node, because such a range is structurally meaningless and would break traversal logic (range iteration stops at the terminal node).","triggerScenarios":"Calling `new GameFrameworkLinkedListRange<T>(null, terminal)`, `(first, null)`, or `(node, node)` with the same LinkedListNode<T> for both parameters; also indirectly via any API that builds a range from empty or malformed linked-list state.","commonSituations":"Creating a range from a node obtained from an empty list (Find returns null), or accidentally passing the terminal sentinel as the first node; storing ranges across list modifications that orphaned the nodes.","solutions":["Obtain first and terminal nodes from the same non-empty LinkedList<T>, ensuring first != terminal.","Check that the searched node exists (Find/FindFirst not null) before constructing the range.","Use the list's own range-creation helpers if provided rather than constructing nodes manually.","Catch GameFrameworkException around range construction when node availability is uncertain."],"exampleFix":"// before\nvar range = new GameFrameworkLinkedListRange<int>(list.Find(key), list.First); // may be null/equal\n// after\nvar first = list.Find(key);\nvar terminal = list.First;\nif (first != null && terminal != null && first != terminal)\n{\n    var range = new GameFrameworkLinkedListRange<int>(first, terminal);\n}","handlingStrategy":"validation","validationCode":"if (first == null || terminal == null || first == terminal) { throw new ArgumentException(\"Range nodes are invalid.\"); }\nvar range = new GameFrameworkLinkedListRange<T>(first, terminal);","typeGuard":"static bool IsValidRange<T>(LinkedListNode<T> first, LinkedListNode<T> terminal) => first != null && terminal != null && first != terminal;","tryCatchPattern":"try { var range = new GameFrameworkLinkedListRange<T>(first, terminal); } catch (GameFrameworkException) { /* skip empty/invalid span */ }","preventionTips":["Always derive first/terminal from the same non-empty list","Check Find() result for null before building a range","Never pass the terminal sentinel as the first node"],"tags":["csharp","invalid-argument-value","linked-list","range"],"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"}