Hmbown/CodeWhale · error

memory search query is empty or too long

Error message

memory search query is empty or too long

What it means

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.

Solutions

  1. Check the query is non-empty and within MAX_QUERY_CHARS before calling search/search_for_workspace
  2. Trim the query first and re-check length after trimming, since validation trims before counting
  3. Show the user a 'query too long / empty' message instead of invoking search

Example fix

// before
memory.search(user_input)
// after
let q = user_input.trim();
if q.is_empty() || q.chars().count() > MAX_QUERY_CHARS { return Err("invalid query"); }
memory.search(q)
Defensive patterns

Strategy: validation

Validate before calling

let q = query.trim();
if q.is_empty() || q.chars().count() > MAX_QUERY_CHARS {
    return Err("memory search query must be 1..=MAX_QUERY_CHARS chars");
}

Type guard

fn is_valid_query(q: &str) -> bool {
    let t = q.trim();
    !t.is_empty() && t.chars().count() <= MAX_QUERY_CHARS
}

Try / catch

match memory.search(query) {
    Ok(results) => results,
    Err(e) if e.to_string().contains("empty or too long") => Vec::new(), // or surface UI hint
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/be61d8bc3f78804f. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/native_memory.rs:899

    let note = note
        .lines()
        .map(str::trim)
        .filter(|line| !line.is_empty())
        .collect::<Vec<_>>()
        .join(" ");
    if note.is_empty() {
        bail!("memory note is empty");
    }
    if note.len() > MAX_NOTE_BYTES {
        bail!("memory note exceeds {MAX_NOTE_BYTES} bytes");
    }
    Ok(note.trim_start_matches('-').trim().to_string())
}

fn validate_query(query: &str) -> Result<&str> {
    let query = query.trim();
    if query.is_empty() || query.chars().count() > MAX_QUERY_CHARS {
        bail!("memory search query is empty or too long");
    }
    Ok(query)
}

fn safe_component(value: &str) -> Result<String> {
    if value.is_empty()
        || value == "."
        || value == ".."
        || value.contains('/')
        || value.contains('\\')
    {
        bail!("invalid memory workspace id");
    }
    Ok(value.to_string())
}

fn ensure_memory_file(path: &Path) -> Result<()> {
    if let Some(parent) = path.parent() {

View on GitHub (pinned to 433685b202)