4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
122 lines
3.5 KiB
Python
122 lines
3.5 KiB
Python
"""Lazy platform shims for CLI analytics, Sentry, error reporting, and landing UI.
|
|
|
|
Each function defers its heavy ``platform``/UI import until called, keeping CLI
|
|
startup cheap. ``surfaces.cli.__main__`` imports these names, so tests patch the
|
|
seam there (e.g. ``surfaces.cli.__main__.capture_cli_invoked``) and the
|
|
entrypoint's own callers pick up the patched global.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
import click
|
|
|
|
if TYPE_CHECKING:
|
|
from platform.analytics.provider import Properties
|
|
from platform.common.errors import OpenSREError
|
|
|
|
|
|
def capture_first_run_if_needed() -> None:
|
|
from platform.analytics.provider import capture_first_run_if_needed as _capture
|
|
|
|
_capture()
|
|
|
|
|
|
def capture_cli_invoked(properties: Properties | None = None) -> None:
|
|
from platform.analytics.cli import capture_cli_invoked as _capture
|
|
|
|
_capture(properties)
|
|
|
|
|
|
def shutdown_analytics(*, flush: bool = False, timeout: float | None = None) -> None:
|
|
from platform.analytics.provider import shutdown_analytics as _shutdown
|
|
|
|
if timeout is None:
|
|
_shutdown(flush=flush)
|
|
else:
|
|
_shutdown(flush=flush, timeout=timeout)
|
|
|
|
|
|
def build_cli_invoked_properties(
|
|
*,
|
|
entrypoint: str,
|
|
command_parts: list[str],
|
|
json_output: bool,
|
|
verbose: bool,
|
|
debug: bool,
|
|
yes: bool,
|
|
interactive: bool,
|
|
) -> Properties:
|
|
from platform.analytics.cli import build_cli_invoked_properties as _build
|
|
|
|
return _build(
|
|
entrypoint=entrypoint,
|
|
command_parts=command_parts,
|
|
json_output=json_output,
|
|
verbose=verbose,
|
|
debug=debug,
|
|
yes=yes,
|
|
interactive=interactive,
|
|
)
|
|
|
|
|
|
def report_exception(exc: BaseException, *, context: str) -> None:
|
|
from surfaces.interactive_shell.utils.error_handling.exception_reporting import (
|
|
report_exception as _report_exception,
|
|
)
|
|
|
|
_report_exception(exc, context=context)
|
|
|
|
|
|
def should_report_exception(exc: click.ClickException) -> bool:
|
|
from surfaces.interactive_shell.utils.error_handling.exception_reporting import (
|
|
should_report_exception as _should_report_exception,
|
|
)
|
|
|
|
return _should_report_exception(exc)
|
|
|
|
|
|
def init_sentry(*, entrypoint: str | None = None) -> None:
|
|
from platform.observability.errors.sentry import init_sentry as _init_sentry
|
|
|
|
_init_sentry(entrypoint=entrypoint)
|
|
|
|
|
|
def capture_exception(exc: BaseException, *, context: str) -> None:
|
|
from platform.observability.errors.sentry import capture_exception as _capture_exception
|
|
|
|
_capture_exception(exc, context=context)
|
|
|
|
|
|
def render_landing(group: click.Group) -> None:
|
|
from surfaces.interactive_shell.ui.layout import render_landing as _render_landing
|
|
|
|
_render_landing(group)
|
|
|
|
|
|
def load_structured_error_type() -> type[OpenSREError]:
|
|
from platform.common.errors import OpenSREError
|
|
|
|
return OpenSREError
|
|
|
|
|
|
def render_structured_error(exc: OpenSREError) -> int:
|
|
"""Render a structured ``OpenSREError`` as a clean panel and return its exit code.
|
|
|
|
Used for structured errors raised by non-CLI code (tools/integrations) that
|
|
are not ``ClickException`` instances, so Click never renders them itself.
|
|
"""
|
|
from rich.console import Console
|
|
|
|
from platform.terminal.errors import render_error
|
|
|
|
hint: str | None = None
|
|
if exc.suggestion:
|
|
parts = [exc.suggestion]
|
|
if exc.docs_url:
|
|
parts.append(f"Docs: {exc.docs_url}")
|
|
hint = " ".join(parts)
|
|
render_error(exc, console=Console(stderr=True, highlight=False), hint=hint)
|
|
return int(exc.exit_code)
|