{"record":{"id":"260e3c75affb294a","repo":"stride3d/stride","slug":"the-deque-is-empty","errorCode":null,"errorMessage":"The deque is empty.","messagePattern":"The deque is empty\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core/Collections/Dequeue.cs","lineNumber":878,"sourceCode":"        CheckRangeArguments(Count, offset, count);\n\n        if (count == 0)\n        {\n            return;\n        }\n\n        DoRemoveRange(offset, count);\n    }\n\n    /// <summary>\n    /// Removes and returns the last element of this deque.\n    /// </summary>\n    /// <returns>The former last element.</returns>\n    /// <exception cref=\"InvalidOperationException\">The deque is empty.</exception>\n    public T RemoveFromBack()\n    {\n        if (IsEmpty)\n            throw new InvalidOperationException(\"The deque is empty.\");\n\n        return DoRemoveFromBack();\n    }\n\n    /// <summary>\n    /// Removes and returns the first element of this deque.\n    /// </summary>\n    /// <returns>The former first element.</returns>\n    /// <exception cref=\"InvalidOperationException\">The deque is empty.</exception>\n    public T RemoveFromFront()\n    {\n        if (IsEmpty)\n            throw new InvalidOperationException(\"The deque is empty.\");\n\n        return DoRemoveFromFront();\n    }\n\n    /// <summary>","sourceCodeStart":860,"sourceCodeEnd":896,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core/Collections/Dequeue.cs#L860-L896","documentation":"Thrown by RemoveFromBack when the deque has no elements. Removing and returning the last element is undefined on an empty deque, so the method fails fast with InvalidOperationException rather than returning a default value.","triggerScenarios":"Calling deque.RemoveFromBack() when IsEmpty is true — typically one more call than the number of AddToFront/AddToAddBack calls, or on a freshly constructed deque.","commonSituations":"Draining loops without checking IsEmpty; queue-consumer code that races ahead of producers in single-threaded pipelines; reusing a deque after Clear() without rechecking emptiness.","solutions":["Check IsEmpty (or Count > 0) before calling RemoveFromBack","Wrap the call in try/catch for InvalidOperationException if drain-until-empty semantics are intended","Prefer TryRemove-type patterns or Count checks inside drain loops"],"exampleFix":"// before\nwhile (true) { var item = deque.RemoveFromBack(); Process(item); } // throws when empty\n// after\nwhile (!deque.IsEmpty) { var item = deque.RemoveFromBack(); Process(item); }","handlingStrategy":"try-catch","validationCode":"if (!deque.IsEmpty) { var item = deque.RemoveFromBack(); ... }","typeGuard":null,"tryCatchPattern":"try { var item = deque.RemoveFromBack(); Process(item); }\ncatch (InvalidOperationException ex) when (ex.Message == \"The deque is empty.\") { /* empty: nothing to remove */ }","preventionTips":["Check IsEmpty before every pop","Drain with while (!deque.IsEmpty) loops","Don't treat the deque as a blocking/concurrent queue"],"tags":["collections","deque","empty","invalid-operation"],"backgroundTag":"empty-required-field","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}