{"record":{"id":"d17a849c58f63f19","repo":"sigoden/aichat","slug":"no-chat-response-to-copy","errorCode":null,"errorMessage":"No chat response to copy","messagePattern":"No chat response to copy","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/repl/mod.rs","lineNumber":672,"sourceCode":"            },\n            \".delete\" => match args {\n                Some(args) => {\n                    Config::delete(config, args)?;\n                }\n                _ => {\n                    println!(\"Usage: .delete <role|session|rag|macro|agent-data>\")\n                }\n            },\n            \".copy\" => {\n                let output = match config\n                    .read()\n                    .last_message\n                    .as_ref()\n                    .filter(|v| !v.output.is_empty())\n                    .map(|v| v.output.clone())\n                {\n                    Some(v) => v,\n                    None => bail!(\"No chat response to copy\"),\n                };\n                set_text(&output).context(\"Failed to copy the last chat response\")?;\n            }\n            \".exit\" => match args {\n                Some(\"role\") => {\n                    config.write().exit_role()?;\n                }\n                Some(\"session\") => {\n                    if config.read().agent.is_some() {\n                        config.write().exit_agent_session()?;\n                    } else {\n                        config.write().exit_session()?;\n                    }\n                }\n                Some(\"rag\") => {\n                    config.write().exit_rag()?;\n                }\n                Some(\"agent\") => {","sourceCodeStart":654,"sourceCodeEnd":690,"githubUrl":"https://github.com/sigoden/aichat/blob/82976d349ad97ac9aae0655ad631dace5e2a6385/src/repl/mod.rs#L654-L690","documentation":"The `.copy` REPL command copies the last chat response to the system clipboard; it requires the last message to have non-empty output. If there is no such response, it bails with 'No chat response to copy'. A subsequent clipboard failure is a separate error ('Failed to copy the last chat response').","triggerScenarios":"Running `.copy` when the session has no last message, or when the last message's output is empty (e.g. filtered out by `.filter` on empty output).","commonSituations":"Typing .copy in a fresh session; copying after .empty session; a response that produced no visible output; running in a terminal/environment where last_message is absent after role switching.","solutions":["Ensure at least one chat response exists in the current session before .copy","Send a message and wait for the reply, then run .copy","Use .last to verify there is a response to copy"],"exampleFix":"// before: .copy right after starting session\n.copy\n// after\nExplain Rc vs Arc\n.copy","handlingStrategy":"try-catch","validationCode":"let has_output = session.last_message.as_ref()\n    .map(|m| !m.output.is_empty())\n    .unwrap_or(false);\nif has_output { repl(\".copy\")?; } else { eprintln!(\"No response to copy yet\"); }","typeGuard":"fn has_copyable_output(last: Option<&LastMessage>) -> bool {\n    last.map(|m| !m.output.is_empty()).unwrap_or(false)\n}","tryCatchPattern":"match repl(\".copy\") {\n    Err(e) if e.to_string() == \"No chat response to copy\" => {\n        eprintln!(\"Ask a question first; .copy needs a prior response\");\n    }\n    other => other?,\n}","preventionTips":["Run .copy only after a chat response is visible","Check clipboard tooling availability separately (copy can still fail after this check)","Don't rely on .copy right after .empty session or role switches"],"tags":["repl","clipboard","session"],"backgroundTag":"empty-result-set","analyzedSha":"82976d349ad97ac9aae0655ad631dace5e2a6385","analyzedAt":"2026-09-09T18:33:06.139Z","contentChangedAt":"2026-09-09T18:33:06.139Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}