{"record":{"id":"d600f3f7212f40c8","repo":"AprilNEA/OpenLogi","slug":"the-sanitized-selected-profile-route-is-absent","errorCode":null,"errorMessage":"the sanitized selected profile route is absent","messagePattern":"the sanitized selected profile route is absent","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/openlogi-cli/src/cmd/fixture/record_profile.rs","lineNumber":257,"sourceCode":"        .collect::<Result<Vec<_>>>()?;\n    let retained_selected = if retained.receiver.unique_id.is_none() {\n        0\n    } else {\n        selected_device\n    };\n    sanitize::inventory(&mut retained)?;\n    let profile_routes = retained\n        .paired\n        .iter()\n        .map(|device| {\n            DeviceRoute::device_route_for(&retained, device.slot)\n                .ok_or_else(|| anyhow!(\"a sanitized profile route is not addressable\"))\n        })\n        .collect::<Result<Vec<_>>>()?;\n    let selected_route = profile_routes\n        .get(retained_selected)\n        .cloned()\n        .ok_or_else(|| anyhow!(\"the sanitized selected profile route is absent\"))?;\n\n    let mut settings = Vec::with_capacity(retained.paired.len());\n    for ((source_route, profile_route), device) in source_routes\n        .iter()\n        .zip(profile_routes)\n        .zip(&retained.paired)\n    {\n        settings.push(capture_hidpp_settings(client, source_route, profile_route, device).await?);\n    }\n    Ok((vec![retained], Vec::new(), settings, selected_route))\n}\n\nasync fn capture_hidpp_settings(\n    client: &AgentClient,\n    source_route: &DeviceRoute,\n    profile_route: DeviceRoute,\n    device: &PairedDevice,\n) -> Result<ProfileDeviceSettings> {","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/AprilNEA/OpenLogi/blob/e846e6f4b4405e33bd6a9aaf949a482ce34cb6d8/crates/openlogi-cli/src/cmd/fixture/record_profile.rs#L239-L275","documentation":"Raised in `capture_inventory` when `profile_routes.get(retained_selected)` is `None` — the index of the selected device does not resolve into the sanitized route list. Since `retained_selected` is derived from `selected_device` (or forced to 0 for direct devices) and `profile_routes` mirrors `retained.paired`, this means sanitization changed the paired list length/order relative to the selection index.","triggerScenarios":"`capture_inventory` computes `retained_selected = selected_device` for receiver-backed inventories, then `sanitize::inventory` prunes or reorders `retained.paired` so the selected index no longer exists in the sanitized list.","commonSituations":"Sanitizer pruning drops devices before the selected one (shifting indices) or drops the selected device itself; selecting a device index from pre-sanitize data and applying it post-sanitize.","solutions":["Fix `sanitize::inventory` to keep the selected device or to remap the selected index rather than leaving it stale.","Ensure the selected index is only computed after sanitization, or adjusted when sanitizer removes devices.","As a user, retry with an explicit `--device` selector on a fresh snapshot; if it persists, it is a CLI sanitizer bug."],"exampleFix":"// before: index computed before sanitize, used after\nlet retained_selected = selected_device;\nsanitize::inventory(&mut retained)?;\n// after: remap selection through sanitize, or sanitize first then reselect\nsanitize::inventory(&mut retained)?;\nlet retained_selected = retained.paired.iter().position(|d| d.slot == original_slot).ok_or_else(|| anyhow!(\"selected device was pruned during sanitization\"))?;","handlingStrategy":"validation","validationCode":"let retained_selected = retained.paired.iter().position(|d| d.slot == original_slot)\n    .ok_or_else(|| anyhow!(\"selected device pruned during sanitization\"))?;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Track the selected device by slot (stable identity), not by positional index, across sanitization.","Compute the selected route after sanitization completes.","Add a test where the sanitizer prunes devices before the selected one."],"tags":["rust","cli","sanitization","index-out-of-bounds"],"backgroundTag":"index-out-of-bounds","analyzedSha":"e846e6f4b4405e33bd6a9aaf949a482ce34cb6d8","analyzedAt":"2026-09-13T03:07:16.451Z","contentChangedAt":"2026-09-13T03:07:16.451Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}