{"record":{"id":"be61d8bc3f78804f","repo":"Hmbown/CodeWhale","slug":"memory-search-query-is-empty-or-too-long","errorCode":null,"errorMessage":"memory search query is empty or too long","messagePattern":"memory search query is empty or too long","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/native_memory.rs","lineNumber":899,"sourceCode":"    let note = note\n        .lines()\n        .map(str::trim)\n        .filter(|line| !line.is_empty())\n        .collect::<Vec<_>>()\n        .join(\" \");\n    if note.is_empty() {\n        bail!(\"memory note is empty\");\n    }\n    if note.len() > MAX_NOTE_BYTES {\n        bail!(\"memory note exceeds {MAX_NOTE_BYTES} bytes\");\n    }\n    Ok(note.trim_start_matches('-').trim().to_string())\n}\n\nfn validate_query(query: &str) -> Result<&str> {\n    let query = query.trim();\n    if query.is_empty() || query.chars().count() > MAX_QUERY_CHARS {\n        bail!(\"memory search query is empty or too long\");\n    }\n    Ok(query)\n}\n\nfn safe_component(value: &str) -> Result<String> {\n    if value.is_empty()\n        || value == \".\"\n        || value == \"..\"\n        || value.contains('/')\n        || value.contains('\\\\')\n    {\n        bail!(\"invalid memory workspace id\");\n    }\n    Ok(value.to_string())\n}\n\nfn ensure_memory_file(path: &Path) -> Result<()> {\n    if let Some(parent) = path.parent() {","sourceCodeStart":881,"sourceCodeEnd":917,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/crates/tui/src/native_memory.rs#L881-L917","documentation":"native_memory.rs validates memory search queries in validate_query before performing any search. The query is trimmed; if it is empty after trimming or longer than MAX_QUERY_CHARS characters, the search is rejected. This guards the search index/filesystem from meaningless or oversized requests.","triggerScenarios":"Calling native_memory search or search_for_workspace with an empty string, a whitespace-only string, or a query longer than MAX_QUERY_CHARS characters.","commonSituations":"Passing an untrimmed variable that is actually blank; building a query from empty user input or an unset config field; concatenating filters so the query exceeds the character limit; UI submit on an empty search box.","solutions":["Check the query is non-empty and within MAX_QUERY_CHARS before calling search/search_for_workspace","Trim the query first and re-check length after trimming, since validation trims before counting","Show the user a 'query too long / empty' message instead of invoking search"],"exampleFix":"// before\nmemory.search(user_input)\n// after\nlet q = user_input.trim();\nif q.is_empty() || q.chars().count() > MAX_QUERY_CHARS { return Err(\"invalid query\"); }\nmemory.search(q)","handlingStrategy":"validation","validationCode":"let q = query.trim();\nif q.is_empty() || q.chars().count() > MAX_QUERY_CHARS {\n    return Err(\"memory search query must be 1..=MAX_QUERY_CHARS chars\");\n}","typeGuard":"fn is_valid_query(q: &str) -> bool {\n    let t = q.trim();\n    !t.is_empty() && t.chars().count() <= MAX_QUERY_CHARS\n}","tryCatchPattern":"match memory.search(query) {\n    Ok(results) => results,\n    Err(e) if e.to_string().contains(\"empty or too long\") => Vec::new(), // or surface UI hint\n    Err(e) => return Err(e),\n}","preventionTips":["Trim and check user input before invoking search","Enforce a max-length in the UI layer (maxlength attribute) matching MAX_QUERY_CHARS","Treat whitespace-only input as a no-op instead of a search call"],"tags":["validation","memory-search","input-length"],"backgroundTag":"empty-required-field","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}