docs: Simplify verbose docstrings
- save_map_file(): 55 lines → 12 lines - is_legacy_backend(): 42 lines → 11 lines - _check_response_for_errors(): 40 lines → 9 lines Keep essential info, remove redundant examples and explanations. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -91,43 +91,12 @@ def haproxy_cmd_checked(command: str) -> str:
|
||||
def _check_response_for_errors(response: str) -> None:
|
||||
"""Check HAProxy response for error indicators and raise if found.
|
||||
|
||||
HAProxy Runtime API returns plain text responses. Success responses are
|
||||
typically empty or contain requested data. Error responses contain
|
||||
specific keywords that indicate the command failed.
|
||||
|
||||
Args:
|
||||
response: Response string from HAProxy Runtime API command.
|
||||
response: Response string from HAProxy Runtime API.
|
||||
|
||||
Raises:
|
||||
HaproxyError: If response contains any error indicator keyword.
|
||||
|
||||
Error Indicators:
|
||||
- "No such": Resource doesn't exist (e.g., backend, server, map entry)
|
||||
- "not found": Similar to "No such", resource lookup failed
|
||||
- "error": General error in command execution
|
||||
- "failed": Operation could not be completed
|
||||
- "invalid": Malformed command or invalid parameter value
|
||||
- "unknown": Unrecognized command or parameter
|
||||
|
||||
Examples:
|
||||
Successful responses (will NOT raise):
|
||||
- "" (empty string for successful set commands)
|
||||
- "1" (map entry ID after successful add)
|
||||
- Server state data (for show commands)
|
||||
|
||||
Error responses (WILL raise HaproxyError):
|
||||
- "No such server." - Server doesn't exist in specified backend
|
||||
- "No such backend." - Backend name not found
|
||||
- "No such map." - Map file not loaded or doesn't exist
|
||||
- "Entry not found." - Map entry lookup failed
|
||||
- "Invalid server state." - Bad state value for set server state
|
||||
- "unknown keyword 'xyz'" - Unrecognized command parameter
|
||||
- "failed to allocate memory" - Resource allocation failure
|
||||
- "'set server' expects <addr>:<port>" - Invalid command syntax
|
||||
|
||||
Note:
|
||||
The check is case-insensitive to catch variations like "Error:",
|
||||
"ERROR:", "error:" etc. that HAProxy may return.
|
||||
HaproxyError: If response contains error keywords
|
||||
(No such, not found, error, failed, invalid, unknown).
|
||||
"""
|
||||
error_indicators = ["No such", "not found", "error", "failed", "invalid", "unknown"]
|
||||
if response:
|
||||
|
||||
Reference in New Issue
Block a user