openwebui-cli/openwebui_cli/errors.py
Danny Stocker 8530f74687 Initial CLI scaffolding with v1.0 MVP structure
Complete Python CLI for OpenWebUI with:
- Auth commands (login, logout, whoami, token, refresh)
- Chat send with streaming support
- RAG files/collections management
- Models list/info
- Admin stats (minimal v1.0)
- Config management with profiles and keyring

Stack: typer, httpx, rich, pydantic, keyring

Based on RFC v1.2 with 22-step implementation checklist

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 20:09:19 +01:00

60 lines
1.3 KiB
Python

"""CLI error classes with standardized exit codes."""
import sys
from enum import IntEnum
class ExitCode(IntEnum):
"""Standardized exit codes for the CLI."""
SUCCESS = 0
GENERAL_ERROR = 1
USAGE_ERROR = 2
AUTH_ERROR = 3
NETWORK_ERROR = 4
SERVER_ERROR = 5
class CLIError(Exception):
"""Base exception for CLI errors."""
exit_code: int = ExitCode.GENERAL_ERROR
def __init__(self, message: str, exit_code: int | None = None):
super().__init__(message)
if exit_code is not None:
self.exit_code = exit_code
class UsageError(CLIError):
"""Invalid command usage or arguments."""
exit_code = ExitCode.USAGE_ERROR
class AuthError(CLIError):
"""Authentication or authorization failure."""
exit_code = ExitCode.AUTH_ERROR
class NetworkError(CLIError):
"""Network connectivity or timeout error."""
exit_code = ExitCode.NETWORK_ERROR
class ServerError(CLIError):
"""Server returned an error (5xx)."""
exit_code = ExitCode.SERVER_ERROR
def handle_error(error: Exception) -> int:
"""Handle an error and return the appropriate exit code."""
if isinstance(error, CLIError):
print(f"Error: {error}", file=sys.stderr)
return error.exit_code
else:
print(f"Unexpected error: {error}", file=sys.stderr)
return ExitCode.GENERAL_ERROR