spacedriveapp/spacedrive · warning · anyhow::Error
Invalid choice selected
Error message
Invalid choice selected
What it means
After the conflict prompt, the match handles indices 0 (Overwrite), 1 (AutoModifyName), and 2 (Abort), with a catch-all `_` arm bailing 'Invalid choice selected'. The prompt implementation (`prompt_for_choice` in apps/cli/src/util/confirm.rs:37) loops until it gets a number in 1..=len and returns a 0-based index, so with the standard three choices this arm is unreachable. Hitting it means the choice list was changed (more resolutions added to FileConflictResolution::CHOICES without updating the match) or the prompt was bypassed in testing.
Source
Thrown at apps/cli/src/domains/file/mod.rs:162
// Apply the user's choice to the input
match choice_index {
0 => {
// Overwrite: set conflict resolution in input
use sd_core::ops::files::copy::action::FileConflictResolution;
input.on_conflict = Some(FileConflictResolution::Overwrite);
}
1 => {
// Auto-rename: set conflict resolution in input
use sd_core::ops::files::copy::action::FileConflictResolution;
input.on_conflict = Some(FileConflictResolution::AutoModifyName);
}
2 => {
// Abort
anyhow::bail!("Operation aborted by user");
}
_ => {
anyhow::bail!("Invalid choice selected");
}
}
}
}
// Execute the action using the input
let job_id: JobId = execute_action!(ctx, input);
Ok(job_id)
}
/// Simple conflict detection for CLI
async fn check_for_simple_conflicts(
action: &sd_core::ops::files::copy::action::FileCopyAction,
) -> Result<bool> {
use sd_core::domain::addressing::SdPath;
// Extract the physical path from the destination SdPath
let dest_path = match &action.destination {View on GitHub (pinned to 6dfeccf211)
Solutions
- For users: this is a code defect, not an input mistake — report it with the CLI version.
- For maintainers: replace numeric indices with an exhaustive match over the choices, e.g. map FileConflictResolution::from_index(idx) and add a unit test covering len(CHOICES).
- Verify any local patches to confirm.rs or the CHOICES list are in sync.
Example fix
// before: numeric arms, silently breaks when CHOICES grows
match prompt_for_choice(request)? { 0 => ..., 1 => ..., 2 => ..., _ => anyhow::bail!("Invalid choice selected") }
// after: exhaustively map every registered choice
let idx = prompt_for_choice(request)?;
let resolution = FileConflictResolution::CHOICES.get(idx).copied().ok_or_else(|| anyhow::anyhow!("Unknown conflict choice at index {}", idx))?;
input.on_conflict = Some(resolution); Defensive patterns
Strategy: try-catch
Try / catch
match run_copy_with_confirmation(ctx, input).await {
Err(e) if e.to_string().contains("Invalid choice selected") => {
// unreachable via the real prompt — treat as a bug report, not user error
report_bug("conflict CHOICES out of sync with match arms");
return Err(e);
}
other => other?,
} Prevention
- When extending FileConflictResolution::CHOICES, update the match arms in the same commit and add a test over all indices.
- Prefer exhaustive mapping via CHOICES.get(idx) over hardcoded numeric arms.
- Test harnesses stubbing prompt_for_choice must clamp return values to 0..len(CHOICES).
When it happens
Trigger: A maintainer adds a fourth FileConflictResolution variant; CHOICES grows, prompt returns index 3, and the match's `_` arm fires. Cannot be triggered by typing anything at the real prompt.
Common situations: Regression after extending conflict-resolution options; test harnesses that stub prompt_for_choice and return out-of-range indices.
Related errors
- Operation aborted by user
- Failed to build action: {}
- Invalid sort option: {}. Valid options are: name, modified,
- Non-local address not supported for indexing yet: {}
- Non-local path not supported yet
AI-assisted analysis of spacedriveapp/spacedrive@6dfeccf211 (2026-08-16).
Data as JSON: /api/errors/130dad1f92566b58.
Report an issue: GitHub.