{"record":{"id":"f4db32f0c7b1cad3","repo":"tonhowtf/omniget","slug":"grok-f4db32","errorCode":null,"errorMessage":"Grok: {}","messagePattern":"Grok: \\{\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/x/grok.rs","lineNumber":374,"sourceCode":"        for key in [\"cited_web_results\", \"webResults\", \"citedWebResults\"] {\n            for w in r.get(key).and_then(|a| a.as_array()).into_iter().flatten() {\n                if let Some(url) = w.get(\"url\").and_then(|u| u.as_str()) {\n                    if !citations.iter().any(|c| c.url == url) {\n                        citations.push(Citation {\n                            url: url.to_string(),\n                            title: w\n                                .get(\"title\")\n                                .and_then(|t| t.as_str())\n                                .unwrap_or(\"\")\n                                .to_string(),\n                        });\n                    }\n                }\n            }\n        }\n        if let Some(err) = r.get(\"error\").and_then(|e| e.as_str()) {\n            if text.is_empty() {\n                return Err(anyhow!(\"Grok: {}\", err));\n            }\n        }\n    }\n    if text.trim().is_empty() {\n        return Err(anyhow!(\n            \"Grok nao respondeu (modelo `{}` pode nao existir mais; troque nas opcoes)\",\n            model\n        ));\n    }\n    Ok(GrokAnswer {\n        text,\n        citations,\n        model,\n        backend: \"x\".into(),\n        input_tokens: 0,\n        output_tokens: 0,\n    })\n}","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/x/grok.rs#L356-L392","documentation":"While parsing the NDJSON stream from add_response.json, if a result chunk contains an \"error\" field and no assistant text has accumulated yet, ask_x aborts with `Grok: <error>`. This is Grok itself (via the X session) reporting a failure — e.g. the model rejected the request — before producing any output.","triggerScenarios":"A streamed result chunk carries r.error (as a string) while text is empty: invalid grokModelOptionId, Grok refusing the prompt (content policy), conversation state errors, or X-side Grok service errors delivered mid-stream.","commonSituations":"Configured x_model id no longer offered by X; prompt flagged by Grok's safety filters; X Grok backend outage; sending a system prompt or features the selected model does not support.","solutions":["Read the embedded Grok error text after the `Grok: ` prefix — it states the server-side reason.","If it indicates an unknown/invalid model, change x_model in grok.json (or pass req.model) to a currently valid option id.","Rephrase the prompt if it was refused by content filtering.","Retry later if it is a transient X/Grok service error.","Fall back to the xai backend with an xai_key for a stable API."],"exampleFix":"// before\n\"grokModelOptionId\": \"grok-2-old-id\"  // -> chunk error: model not found\n// after\n\"grokModelOptionId\": \"grok-3\"         // current valid option id","handlingStrategy":"try-catch","validationCode":"// validate model id before sending\nif !model_option_ids_known_good().contains(&cfg.x_model) { return Err(\"x_model option id unknown\"); }","typeGuard":"fn chunk_error(v: &serde_json::Value) -> Option<&str> {\n    v.get(\"result\").and_then(|r| r.get(\"error\")).and_then(|e| e.as_str())\n}","tryCatchPattern":"match grok::ask(req).await {\n    Ok(a) => use_answer(a),\n    Err(e) if e.to_string().starts_with(\"Grok: \") => {\n        let reason = e.to_string().trim_start_matches(\"Grok: \");\n        switch_model_or_backend(req, reason)\n    }\n    Err(e) => log_error(e),\n}","preventionTips":["Keep x_model set to a model id currently offered on x.com/i/grok","Avoid prompts likely to trip Grok's content filters","Treat the embedded Grok error string as authoritative for the cause","Keep an xai_key configured as a stable fallback backend"],"tags":["streaming","x","grok","api"],"backgroundTag":"api-error-response","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"}