{"record":{"id":"3849c96e8c131d61","repo":"tonhowtf/omniget","slug":"busca-vazia","errorCode":null,"errorMessage":"busca vazia","messagePattern":"busca vazia","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/x/search.rs","lineNumber":22,"sourceCode":"//! falhar, no `SearchTimeline` do GraphQL.\n\nuse serde::{Deserialize, Serialize};\nuse serde_json::json;\n\nuse super::XPost;\n\n#[derive(Debug, Clone, Serialize, Deserialize)]\npub struct SearchPage {\n    pub posts: Vec<XPost>,\n    pub cursor: Option<String>,\n    pub source: String,\n}\n\n/// `feed`: \"latest\" | \"top\".\npub async fn search(query: &str, feed: &str, cursor: Option<&str>) -> anyhow::Result<SearchPage> {\n    let q = query.trim();\n    if q.is_empty() {\n        anyhow::bail!(\"busca vazia\");\n    }\n    let feed = if feed == \"top\" { \"top\" } else { \"latest\" };\n    match super::fx::search(q, feed, cursor).await {\n        Ok(page) => Ok(SearchPage {\n            posts: page.items,\n            cursor: page.cursor,\n            source: \"fxtwitter\".into(),\n        }),\n        Err(fx_err) => {\n            let client = super::client::XClient::new()?;\n            if !client.authed() {\n                return Err(fx_err);\n            }\n            let mut vars = json!({\n                \"rawQuery\": q,\n                \"count\": 40,\n                \"querySource\": \"typed_query\",\n                \"product\": if feed == \"top\" { \"Top\" } else { \"Latest\" },","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/x/search.rs#L4-L40","documentation":"Input validation in the X/Twitter search: search() bails out when the query, after trimming, is an empty string. It fires when a caller invokes the search with a blank query (e.g. an empty or whitespace-only search box value), before any GraphQL timeline request is made.","triggerScenarios":"Calling search(\"\", feed, cursor) or search(\"   \", ...) — a whitespace-only or empty query string passed from the UI or an upstream parser.","commonSituations":"Front-end sending an empty search box value; a command stripping a flag value; an empty query after normalization/trimming in calling code.","solutions":["Validate the query is non-empty before calling search().","In UI code, disable the search action until input is non-blank.","If empty search is meant to list trending/default feed, use the appropriate feed API instead of search()."],"exampleFix":"// before\nlet page = search(&user_input, \"latest\", None).await?;\n// after\nlet q = user_input.trim();\nif q.is_empty() {\n    return Err(anyhow::anyhow!(\"informe um termo de busca\"));\n}\nlet page = search(q, \"latest\", None).await?;","handlingStrategy":"validation","validationCode":"if query.trim().is_empty() {\n    return Err(anyhow::anyhow!(\"query obrigatoria\"));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Trim and check user input at the boundary (UI/CLI) before calling search().","Disable search buttons/actions while the input is blank.","Use the default feed endpoint for 'show me posts' flows instead of an empty search."],"tags":["validation","input","empty-string"],"backgroundTag":"empty-required-field","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}