find_failed_transactions
Identify failed package transactions in pacman logs to troubleshoot installation issues on Arch Linux systems.
Instructions
Find failed package transactions in pacman log. Only works on Arch Linux.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/arch_ops_server/logs.py:210-275 (handler)The core handler function implementing find_failed_transactions. Parses /var/log/pacman.log for lines containing error keywords, extracts timestamps and severity, limits to 100 most recent, and returns structured failure data.async def find_failed_transactions() -> Dict[str, Any]: """ Find failed package transactions in pacman log. Returns: Dict with failed transaction information """ if not IS_ARCH: return create_error_response( "NotSupported", "This feature is only available on Arch Linux" ) logger.info("Searching for failed transactions") try: pacman_log = Path(PACMAN_LOG) if not pacman_log.exists(): return create_error_response( "NotFound", f"Pacman log file not found at {PACMAN_LOG}" ) failed_transactions = [] error_keywords = ["error", "failed", "warning", "could not", "unable to", "conflict"] with open(pacman_log, 'r') as f: for line in f: line_lower = line.lower() # Check for error indicators if any(keyword in line_lower for keyword in error_keywords): # Extract timestamp if available timestamp_match = re.match(r'\[(\d{4}-\d{2}-\d{2})\s+(\d{2}:\d{2})\]', line) timestamp = "" if timestamp_match: timestamp = f"{timestamp_match.group(1)}T{timestamp_match.group(2)}:00" # Extract severity severity = "error" if "error" in line_lower or "failed" in line_lower else "warning" failed_transactions.append({ "timestamp": timestamp, "severity": severity, "message": line.strip() }) # Limit to most recent 100 failures failed_transactions = failed_transactions[-100:] logger.info(f"Found {len(failed_transactions)} failed/warning entries") return { "count": len(failed_transactions), "has_failures": len(failed_transactions) > 0, "failures": failed_transactions } except Exception as e: logger.error(f"Failed to search for failures: {e}") return create_error_response( "LogParseError", f"Failed to search for failed transactions: {str(e)}" )
- src/arch_ops_server/server.py:1032-1039 (registration)MCP tool registration in list_tools(), including name, description, and empty input schema (no parameters required).Tool( name="find_failed_transactions", description="[HISTORY] Find failed package transactions in pacman log. Only works on Arch Linux.", inputSchema={ "type": "object", "properties": {} } ),
- src/arch_ops_server/server.py:1397-1402 (registration)Dispatch logic in call_tool() that checks IS_ARCH and calls the find_failed_transactions function from logs.py, serializing result to JSON.elif name == "find_failed_transactions": if not IS_ARCH: return [TextContent(type="text", text="Error: find_failed_transactions only available on Arch Linux systems")] result = await find_failed_transactions() return [TextContent(type="text", text=json.dumps(result, indent=2))]
- Tool metadata defining category, platform requirements, permissions, workflow, and related tools."find_failed_transactions": ToolMetadata( name="find_failed_transactions", category="history", platform="arch", permission="read", workflow="debug", related_tools=["get_transaction_history"], prerequisite_tools=[]
- src/arch_ops_server/__init__.py:54-54 (registration)Import of find_failed_transactions from .logs in the package __init__.py for re-export.find_failed_transactions,