Enhanced error snapshot function supporting rich context capture. This function bridges the simple interface with the comprehensive snapshot system, allowing callers to pass exception objects and locator states for debugging. Args: error_name: Error name with optional req_
(
error_name: str = "error",
error_exception: Optional[Exception] = None,
error_stage: str = "",
additional_context: Optional[Dict[str, Any]] = None,
locators: Optional[Dict[str, Locator]] = None,
)
| 700 | |
| 701 | |
| 702 | async def save_error_snapshot_enhanced( |
| 703 | error_name: str = "error", |
| 704 | error_exception: Optional[Exception] = None, |
| 705 | error_stage: str = "", |
| 706 | additional_context: Optional[Dict[str, Any]] = None, |
| 707 | locators: Optional[Dict[str, Locator]] = None, |
| 708 | ) -> None: |
| 709 | """ |
| 710 | Enhanced error snapshot function supporting rich context capture. |
| 711 | |
| 712 | This function bridges the simple interface with the comprehensive snapshot system, |
| 713 | allowing callers to pass exception objects and locator states for debugging. |
| 714 | |
| 715 | Args: |
| 716 | error_name: Error name with optional req_id suffix (e.g., "clear_chat_error_hbfu521") |
| 717 | error_exception: The exception that triggered the snapshot (optional) |
| 718 | error_stage: Description of the error stage (optional) |
| 719 | additional_context: Extra context dict to include in metadata (optional) |
| 720 | locators: Dict of named locators to capture states for (optional) |
| 721 | """ |
| 722 | from api_utils.server_state import state |
| 723 | |
| 724 | # Parse req_id from error_name if present (format: "error_name_req_id") |
| 725 | name_parts = error_name.split("_") |
| 726 | req_id = ( |
| 727 | name_parts[-1] |
| 728 | if len(name_parts) > 1 and len(name_parts[-1]) == 7 |
| 729 | else "unknown" |
| 730 | ) |
| 731 | base_error_name = error_name if req_id == "unknown" else "_".join(name_parts[:-1]) |
| 732 | |
| 733 | page_to_snapshot = state.page_instance |
| 734 | |
| 735 | if ( |
| 736 | not hasattr(state, "browser_instance") |
| 737 | or not state.browser_instance |
| 738 | or not state.browser_instance.is_connected() |
| 739 | or not page_to_snapshot |
| 740 | or page_to_snapshot.is_closed() |
| 741 | ): |
| 742 | logger.warning( |
| 743 | f"[{req_id}] Browser/page unavailable ({base_error_name}), saving minimal snapshot..." |
| 744 | ) |
| 745 | # Fallback to minimal snapshot |
| 746 | from browser_utils.operations_modules.errors import save_minimal_snapshot |
| 747 | |
| 748 | await save_minimal_snapshot( |
| 749 | error_name=base_error_name, |
| 750 | req_id=req_id, |
| 751 | error_exception=error_exception, |
| 752 | additional_context=additional_context, |
| 753 | ) |
| 754 | return |
| 755 | |
| 756 | # Merge additional context with exception info |
| 757 | merged_context = additional_context.copy() if additional_context else {} |
| 758 | |
| 759 | # Add exception details to context if provided |