{"record":{"id":"e2dc832f5d18b8bf","repo":"spacedriveapp/spacedrive","slug":"invalid-sort-option-valid-options-are-name","errorCode":null,"errorMessage":"Invalid sort option: {}. Valid options are: name, modified, size, type","messagePattern":"Invalid sort option: (.+?)\\. Valid options are: name, modified, size, type","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"apps/cli/src/domains/file/mod.rs","lineNumber":60,"sourceCode":"\t\t\tprint_output!(ctx, &file_info, |info: &Option<sd_core::domain::File>| {\n\t\t\t\tmatch info {\n\t\t\t\t\tSome(file) => {\n\t\t\t\t\t\tprintln!(\"{}\", serde_json::to_string_pretty(file).unwrap());\n\t\t\t\t\t}\n\t\t\t\t\tNone => {\n\t\t\t\t\t\tprintln!(\"File not found or not indexed in Spacedrive\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t\tFileCmd::List(args) => {\n\t\t\tlet sort_by = match args.sort_by.to_lowercase().as_str() {\n\t\t\t\t\"name\" => sd_core::ops::files::query::DirectorySortBy::Name,\n\t\t\t\t\"modified\" => sd_core::ops::files::query::DirectorySortBy::Modified,\n\t\t\t\t\"size\" => sd_core::ops::files::query::DirectorySortBy::Size,\n\t\t\t\t\"type\" => sd_core::ops::files::query::DirectorySortBy::Type,\n\t\t\t\t_ => {\n\t\t\t\t\tanyhow::bail!(\n\t\t\t\t\t\t\"Invalid sort option: {}. Valid options are: name, modified, size, type\",\n\t\t\t\t\t\targs.sort_by\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t};\n\t\t\tlet directory_listing =\n\t\t\t\tlist_directory(ctx, &args.path, args.limit, args.include_hidden, sort_by).await?;\n\t\t\tprint_output!(\n\t\t\t\tctx,\n\t\t\t\t&directory_listing,\n\t\t\t\t|listing: &sd_core::ops::files::query::DirectoryListingOutput| {\n\t\t\t\t\tprintln!(\"Directory: {}\", args.path.display());\n\t\t\t\t\tprintln!(\"Found {} items:\", listing.files.len());\n\t\t\t\t\tprintln!();\n\n\t\t\t\t\t// Create a table to display the results\n\t\t\t\t\tlet mut table = comfy_table::Table::new();\n\t\t\t\t\ttable.load_preset(UTF8_BORDERS_ONLY);","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/apps/cli/src/domains/file/mod.rs#L42-L78","documentation":"`sd-cli file list --sort-by <value>` lowercases the value and matches it against the four supported `DirectorySortBy` variants (name, modified, size, type). Any other string bails with this message before the directory query is dispatched to the core, so nothing is listed and the daemon is never contacted.","triggerScenarios":"Passing natural but unsupported keys such as `--sort-by date`, `--sort-by created`, `--sort-by name-desc`, or a typo like `--sort-by siez`; note the check is case-insensitive so `Name` works but `name ` (trailing whitespace) does not.","commonSituations":"Users assuming the CLI accepts the same sort keys as the desktop UI; scripts ported from other tools (e.g. `ls -t` habits) that map to 'time' rather than 'modified'.","solutions":["Use one of the four accepted values exactly: name, modified, size, type (case-insensitive).","Check `sd-cli file list --help` for the accepted options of your build.","As a maintainer, replace the free-text String arg with a clap ValueEnum so invalid values are rejected at parse time with a proper usage message."],"exampleFix":"// before (apps/cli/src/domains/file/args.rs + mod.rs)\npub sort_by: String,\nlet sort_by = match args.sort_by.to_lowercase().as_str() { /* ... */ _ => anyhow::bail!(\"Invalid sort option: {}...\") };\n\n// after: clap validates at parse time\n#[derive(clap::ValueEnum, Clone, Copy)]\npub enum SortByArg { Name, Modified, Size, Type }\n#[arg(long, value_enum, default_value_t = SortByArg::Name)]\npub sort_by: SortByArg,\n// then map without a failing arm\nlet sort_by = match args.sort_by { SortByArg::Name => DirectorySortBy::Name, SortByArg::Modified => DirectorySortBy::Modified, SortByArg::Size => DirectorySortBy::Size, SortByArg::Type => DirectorySortBy::Type };","handlingStrategy":"validation","validationCode":"fn parse_sort(v: &str) -> Option<DirectorySortBy> {\n    match v.trim().to_lowercase().as_str() {\n        \"name\" => Some(DirectorySortBy::Name),\n        \"modified\" => Some(DirectorySortBy::Modified),\n        \"size\" => Some(DirectorySortBy::Size),\n        \"type\" => Some(DirectorySortBy::Type),\n        _ => None,\n    }\n}\n// before dispatching:\nlet sort_by = parse_sort(&raw).ok_or_else(|| anyhow::anyhow!(\"sort must be name|modified|size|type\"))?;","typeGuard":"pub fn is_valid_sort(v: &str) -> bool {\n    matches!(v.trim().to_lowercase().as_str(), \"name\" | \"modified\" | \"size\" | \"type\")\n}","tryCatchPattern":"match run_list(args).await {\n    Err(e) if e.to_string().contains(\"Invalid sort option\") => { print_usage_sort(); Err(e) }\n    other => other,\n}","preventionTips":["Always take the four literal values from `--help` rather than guessing synonyms like date/time.","Trim whitespace when building sort strings programmatically.","Maintainers: switch the arg to clap ValueEnum so this class of error disappears at parse time."],"tags":["cli","file-list","sort","input-validation","clap"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}