{"record":{"id":"85e17e9ac79215f4","repo":"nikivdev/code","slug":"query-cannot-be-empty","errorCode":null,"errorMessage":"Query cannot be empty","messagePattern":"Query cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/branches.rs","lineNumber":52,"sourceCode":"\nfn run_list(opts: BranchListOpts) -> Result<()> {\n    let branches = collect_branches(opts.remote)?;\n    if branches.is_empty() {\n        println!(\"No branches found.\");\n        return Ok(());\n    }\n\n    let limit = opts.limit.max(1);\n    for entry in branches.iter().take(limit) {\n        print_branch(entry);\n    }\n    Ok(())\n}\n\nfn run_find(opts: BranchFindOpts) -> Result<()> {\n    let query = opts.query.trim().to_string();\n    if query.is_empty() {\n        bail!(\"Query cannot be empty\");\n    }\n\n    let branches = collect_branches(opts.remote)?;\n    if branches.is_empty() {\n        bail!(\"No branches available to search\");\n    }\n\n    let ranked = rank_branches(&query, &branches);\n    if ranked.is_empty() {\n        bail!(\"No branches matched query '{}'.\", query);\n    }\n\n    let limit = opts.limit.max(1);\n    for (_, entry) in ranked.iter().take(limit) {\n        print_branch(entry);\n    }\n\n    if opts.switch {","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/branches.rs#L34-L70","documentation":"`run_find` (src/branches.rs:52) trims the user-supplied query and rejects it with `bail!(\"Query cannot be empty\")` when nothing remains. The branch-find subcommand requires a non-empty search term; this is input validation before hitting git.","triggerScenarios":"Running the branch find subcommand with an empty or whitespace-only `query` option (e.g. `f branch find --query \"   \"` or omitting the value).","commonSituations":"Shell variable holding the query is empty/unset; user pasted only whitespace; CLI arg parsing dropped the value after a flag.","solutions":["Provide a non-empty query string to the branch find command","Check that any shell variable feeding the query is set and non-blank","Quote the query argument so the shell doesn't swallow it"],"exampleFix":"// before\nf branch find --query \"$Q\"   // Q empty\n// after\n[ -n \"$Q\" ] && f branch find --query \"$Q\"","handlingStrategy":"validation","validationCode":"let query = opts.query.trim();\nif query.is_empty() {\n    anyhow::bail!(\"provide a non-empty branch search query\");\n}","typeGuard":"fn has_query(q: &str) -> bool { !q.trim().is_empty() }","tryCatchPattern":"match run_find(opts) {\n    Err(e) if e.to_string() == \"Query cannot be empty\" => {\n        eprintln!(\"usage: f branch find --query <text>\");\n    }\n    other => other?,\n}","preventionTips":["Always pass an explicit, quoted query argument","In scripts, assert the query variable is non-empty before invoking","Require the query flag (required rather than optional) in the CLI definition"],"tags":["validation","cli","input"],"backgroundTag":"empty-query-validation","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}