{"record":{"id":"664965940d569d10","repo":"crossbeam-rs/crossbeam","slug":"no-operations-have-been-added-to-select","errorCode":null,"errorMessage":"no operations have been added to `Select`","messagePattern":"no operations have been added to `Select`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crossbeam-channel/src/select.rs","lineNumber":479,"sourceCode":"        None => Err(TrySelectError),\n        Some((token, index, addr)) => Ok(SelectedOperation {\n            token,\n            index,\n            addr,\n            _marker: PhantomData,\n        }),\n    }\n}\n\n/// Blocks until one of the operations becomes ready and selects it.\n// This is a private API (exposed inside crossbeam_channel::internal module) that is used by the select macro.\n#[inline]\npub fn select<'a>(\n    handles: &mut [(&'a dyn SelectHandle, usize, usize)],\n    is_biased: bool,\n) -> SelectedOperation<'a> {\n    if handles.is_empty() {\n        panic!(\"no operations have been added to `Select`\");\n    }\n\n    let (token, index, addr) = run_select(handles, Timeout::Never, is_biased).unwrap();\n    SelectedOperation {\n        token,\n        index,\n        addr,\n        _marker: PhantomData,\n    }\n}\n\n/// Blocks for a limited time until one of the operations becomes ready and selects it.\n// This is a private API (exposed inside crossbeam_channel::internal module) that is used by the select macro.\n#[inline]\npub fn select_timeout<'a>(\n    handles: &mut [(&'a dyn SelectHandle, usize, usize)],\n    timeout: Duration,\n    is_biased: bool,","sourceCodeStart":461,"sourceCodeEnd":497,"githubUrl":"https://github.com/crossbeam-rs/crossbeam/blob/38dacb462261fcd64edcb308aed9cbf95c8c82c3/crossbeam-channel/src/select.rs#L461-L497","documentation":"crossbeam-channel's `select!`/internal `select` function panics when the slice of channel operation handles is empty. The select mechanism needs at least one channel operation to wait on; with zero handles there is nothing to select from, so the library treats it as a programmer error and panics rather than returning a result.","triggerScenarios":"Calling `crossbeam_channel::Select::select()` (or `select_timeout()`, or the internal `select()` helper) on a `Select` instance into which no operations were registered via `recv`/`send`, or after the handle slice was drained/emptied.","commonSituations":"Building a `Select` dynamically in a loop where an early branch skips all `recv`/`send` registration calls; conditionally adding operations where all conditions are false; refactoring code that removed the registration but left the `select()` call in place.","solutions":["Register at least one operation with `Select::recv()` or `Select::send()` before calling `select()`","Check `select_instance.handles`-style emptiness (or track registered count yourself) and return early or block on a different mechanism when zero operations exist","If operations are conditional, ensure a default/fallback operation (e.g. a never channel or a timeout case) is always registered"],"exampleFix":"// before\nlet mut sel = Select::new();\nif cond { sel.recv(&rx1); }\nlet oper = sel.select(); // panics if !cond\n\n// after\nlet mut sel = Select::new();\nsel.recv(&rx1); // always register at least one op\nif cond { sel.recv(&rx2); }\nlet oper = sel.select();","handlingStrategy":"validation","validationCode":"if sel_operations_registered == 0 {\n    // skip select, fall back to waiting\n    return;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always register at least one recv/send before select()","Track registration count when building Select dynamically","Prefer the select! macro which encodes at least one branch statically"],"tags":["rust","crossbeam-channel","panic","select"],"backgroundTag":"empty-required-field","analyzedSha":"38dacb462261fcd64edcb308aed9cbf95c8c82c3","analyzedAt":"2026-09-13T03:24:01.537Z","contentChangedAt":"2026-09-13T03:24:01.537Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}