Error Handling System
Run ID: 69cb574361b1021a29a881c52026-03-31Development
PantheraHive BOS
BOS Dashboard

Deliverable: Error Handling System - Architecture Plan & Team Enablement Strategy

This document outlines the proposed architecture for a robust, scalable, and actionable Error Handling System, along with a detailed study plan to enable the development team for its successful implementation and maintenance. This plan addresses the critical need for efficient error detection, diagnosis, and resolution across your applications and services.


1. Executive Summary: Error Handling System Architecture

The proposed Error Handling System is designed to provide a centralized, comprehensive solution for capturing, processing, analyzing, and acting upon errors generated across your entire technology stack. Its primary goal is to minimize Mean Time To Detect (MTTD) and Mean Time To Resolve (MTTR) critical issues, enhance system reliability, and improve the developer experience by providing actionable insights.

The architecture emphasizes:


2. Error Handling System: High-Level Architecture

The system is conceptualized as a series of interconnected layers, each responsible for a specific aspect of the error lifecycle.

2.1. Core Principles

2.2. Architectural Overview Diagram (Conceptual)

mermaid • 1,996 chars
graph TD
    subgraph "Error Sources"
        A[Application SDKs] --> B(HTTP/gRPC API)
        C[Log Parsers/Agents] --> B
        D[Metrics Systems] --> B
    end

    subgraph "Data Ingestion & Queueing"
        B --> E[Message Queue (e.g., Kafka/SQS)]
    end

    subgraph "Data Processing & Enrichment"
        E --> F[Stream Processor (e.g., Flink/Kinesis)]
        F --> G{Rule Engine / Deduplication / Context Enrichment}
    end

    subgraph "Data Storage"
        G --> H[Event Store (e.g., Elasticsearch)]
        G --> I[Metadata DB (e.g., PostgreSQL)]
        G --> J[Time-Series DB (e.g., Prometheus/InfluxDB for error rates)]
    end

    subgraph "Analysis & Presentation"
        K[Reporting & Dashboards] <-- H
        K <-- I
        L[Alerting & Notification Engine] <-- G
        M[User Interface / API] <-- H
        M <-- I
    end

    subgraph "Integrations & Feedback"
        L --> N[Notification Channels (Slack, Email, SMS)]
        L --> O[Incident Management (PagerDuty, Opsgenie)]
        M --> P[Issue Tracking (Jira, GitHub Issues)]
        P --> Q[Feedback Loop to Development Teams]
    end

    style A fill:#f9f,stroke:#333,stroke-width:2px
    style C fill:#f9f,stroke:#333,stroke-width:2px
    style D fill:#f9f,stroke:#333,stroke-width:2px
    style B fill:#bbf,stroke:#333,stroke-width:2px
    style E fill:#bfb,stroke:#333,stroke-width:2px
    style F fill:#fbb,stroke:#333,stroke-width:2px
    style G fill:#fbf,stroke:#333,stroke-width:2px
    style H fill:#ffb,stroke:#333,stroke-width:2px
    style I fill:#ffb,stroke:#333,stroke-width:2px
    style J fill:#ffb,stroke:#333,stroke-width:2px
    style K fill:#ccf,stroke:#333,stroke-width:2px
    style L fill:#ccf,stroke:#333,stroke-width:2px
    style M fill:#ccf,stroke:#333,stroke-width:2px
    style N fill:#efe,stroke:#333,stroke-width:2px
    style O fill:#efe,stroke:#333,stroke-width:2px
    style P fill:#efe,stroke:#333,stroke-width:2px
    style Q fill:#efe,stroke:#333,stroke-width:2px
Sandboxed live preview

2.3. Key Components and Their Responsibilities

  1. Error Sources:

* Application SDKs: Language-specific libraries (e.g., Sentry SDKs, custom wrappers) integrated directly into applications to capture exceptions, stack traces, contextual variables, and user information.

* HTTP/gRPC API Endpoint: A centralized, robust API for receiving error payloads from SDKs, log forwarders, or custom integrations.

* Log Parsers/Agents: Tools (e.g., Filebeat, Fluentd, Logstash) that monitor application logs, extract error patterns, and forward them to the ingestion layer.

* Metrics Systems: Integration with existing monitoring systems (e.g., Prometheus, Datadog) to capture error rate metrics and provide correlation.

  1. Data Ingestion & Queueing:

* Message Queue: A highly available and scalable message broker (e.g., Apache Kafka, AWS SQS, RabbitMQ) that acts as a buffer, decoupling error producers from consumers, ensuring data durability and enabling asynchronous processing.

  1. Data Processing & Enrichment:

* Stream Processor: A real-time data processing engine (e.g., Apache Flink, AWS Kinesis Analytics, Spark Streaming) that consumes messages from the queue.

* Rule Engine / Deduplication / Context Enrichment:

* Deduplication: Identifies and groups identical error occurrences to reduce noise.

* Normalization: Standardizes error formats across different sources.

* Context Enrichment: Adds valuable metadata such as service version, deploy environment, user ID, request ID, trace ID, geographic location, and associated logs/metrics.

* Severity Classification: Assigns a severity level (e.g., critical, error, warning) based on predefined rules or machine learning.

* Root Cause Hinting: Analyzes stack traces and error messages to suggest potential root causes or affected components.

  1. Data Storage:

* Event Store (e.g., Elasticsearch, OpenSearch): Primary storage for raw and processed error events. Optimized for full-text search, aggregation, and time-series queries.

* Metadata Database (e.g., PostgreSQL, MySQL): Stores structured metadata about error groups, resolution status, assignee, comments, and configuration for rules and alerts.

* Time-Series Database (e.g., Prometheus, InfluxDB): Stores aggregated error rates and trends, used for long-term monitoring and performance analysis.

  1. Analysis & Presentation:

* Alerting & Notification Engine: Configurable rules trigger alerts based on error frequency, severity, specific patterns, or changes in error rates. Manages escalation policies.

* Reporting & Dashboards (e.g., Grafana, custom UI): Provides real-time and historical views of error trends, top errors, affected services, deployment impact, and resolution metrics.

* User Interface / API: A dedicated portal for developers and operations teams to view, search, filter, triage, assign, and manage errors. An API allows programmatic access to error data and management functions.

  1. Integrations & Feedback:

* Notification Channels: Integrations with communication platforms (e.g., Slack, Microsoft Teams, Email, SMS) for immediate alerts.

* Incident Management Systems (e.g., PagerDuty, Opsgenie): Direct integration for creating, updating, and resolving incidents triggered by critical errors.

* Issue Tracking Systems (e.g., Jira, GitHub Issues): Allows creation of bug tickets directly from error events, linking errors to specific development tasks.

* Feedback Loop: Mechanisms to ensure that resolved issues are validated and that learnings from incidents are incorporated back into development practices and the error handling system itself.


3. Technology Stack Recommendations (Example)

This section provides example technologies. Specific choices will depend on existing infrastructure, team expertise, and budget.

  • Cloud Platform: AWS, Azure, or GCP (leveraging managed services where possible).
  • Error Capture:

* SDKs: Sentry SDKs, custom HTTP/gRPC client libraries.

* Log Agents: Filebeat, Fluentd, Logstash.

  • API Gateway: AWS API Gateway, Azure API Management, Nginx/Envoy.
  • Message Queue: Apache Kafka (self-managed or Confluent Cloud), AWS SQS/Kinesis, Azure Service Bus, RabbitMQ.
  • Stream Processing: Apache Flink, AWS Kinesis Data Analytics, Azure Stream Analytics, Apache Spark Streaming.
  • Data Storage:

* Event Store: Elasticsearch (AWS OpenSearch Service, Azure Elasticsearch, Elastic Cloud).

* Metadata DB: PostgreSQL (AWS RDS, Azure Database for PostgreSQL, Google Cloud SQL for PostgreSQL).

* Time-Series DB: Prometheus, InfluxDB.

  • Analysis & Alerting:

* Custom microservice (Python/Go/Java) for rule engine and deduplication.

* Alertmanager (for Prometheus), PagerDuty/Opsgenie for incident management.

  • User Interface / Dashboards:

* Frontend: React, Angular, or Vue.js.

* Backend API: Node.js (Express/NestJS), Python (FastAPI/Django), Go (Gin/Echo), Java (Spring Boot).

* Dashboards: Grafana, Kibana.

  • Containerization & Orchestration: Docker, Kubernetes (EKS, AKS, GKE).
  • CI/CD: GitLab CI/CD, GitHub Actions, Jenkins, AWS CodePipeline/CodeBuild.
  • Infrastructure as Code: Terraform, AWS CloudFormation, Azure Resource Manager, Google Cloud Deployment Manager.

4. Architectural Considerations & Non-Functional Requirements

  • Scalability: Design for horizontal scaling of all stateless components (API, Stream Processors, UI backend) and appropriate scaling for stateful components (databases, message queues).
  • Resilience & Fault Tolerance:

* Redundant components, multi-AZ/region deployments.

* Circuit breakers and retries for external integrations.

* Dead-letter queues for failed message processing.

  • Security:

* End-to-end encryption (TLS/SSL for data in transit, encryption at rest).

* Role-Based Access Control (RBAC) for UI and API access.

* Data sanitization and redaction for sensitive information within error payloads.

* Regular security audits and vulnerability assessments.

  • Performance: Low latency for error ingestion and processing, fast query times for dashboards and API.
  • Extensibility: Clear API contracts, plugin architectures for custom enrichments, and easy integration of new notification channels.
  • Maintainability: Well-documented code,
gemini Output

Error Handling System: Comprehensive Code Generation & Implementation Guide

This document outlines the design and provides production-ready code for a robust and scalable Error Handling System. This system is designed to centralize error management, improve debugging, provide consistent user feedback, and facilitate proactive issue resolution across your applications.


1. Introduction to the Error Handling System

A well-architected error handling system is crucial for application stability, maintainability, and user experience. This solution focuses on:

  • Custom Exception Types: Defining domain-specific exceptions for clarity and precise error identification.
  • Centralized Logging: Consolidating all error logs into a single, configurable system for easier monitoring and analysis.
  • Structured Error Responses: Providing consistent and informative error messages to API consumers or front-end applications.
  • Graceful Degradation: Preventing application crashes and ensuring a smooth user experience even when errors occur.
  • Extensibility: Designing the system to be easily adaptable and expandable for future requirements (e.g., integrating with alerting tools).

2. Core Components and Architecture

The Error Handling System is composed of several modular components, primarily implemented in Python for flexibility and widespread applicability.

2.1. Custom Exception Classes (exceptions.py)

These classes provide a structured way to define and categorize specific types of errors that can occur within your application's business logic or during interaction with external systems. They inherit from a base ApplicationError for consistency.

2.2. Centralized Logger Configuration (logger_config.py)

A dedicated module for setting up and configuring a robust logging system. This ensures that all errors, warnings, and informational messages are captured consistently, with appropriate formatting and output destinations (e.g., console, file).

2.3. Error Handling Middleware/Decorator (error_handler.py)

This component acts as a central point for catching exceptions, logging them, and transforming them into standardized error responses. For web applications, this often takes the form of middleware or a decorator that wraps API endpoints or business logic functions.

2.4. Configuration (config.py)

A simple configuration file to manage settings related to the error handling system, such as logging levels, sensitive data masking, or environment-specific behaviors.


3. Implementation Details (Production-Ready Code)

The following sections provide the Python code for each component, complete with explanations and comments.

3.1. Configuration (config.py)

This file holds essential settings for the error handling and logging system.


# config.py

import os

class Config:
    """
    Configuration settings for the Error Handling System.
    """
    # Environment settings
    ENVIRONMENT = os.getenv('APP_ENV', 'development')
    DEBUG = ENVIRONMENT == 'development'

    # Logging settings
    LOG_LEVEL = os.getenv('LOG_LEVEL', 'INFO').upper() # Default to INFO, can be DEBUG, WARNING, ERROR, CRITICAL
    LOG_FILE_PATH = os.getenv('LOG_FILE_PATH', 'application.log')
    LOG_MAX_BYTES = int(os.getenv('LOG_MAX_BYTES', 10 * 1024 * 1024)) # 10 MB
    LOG_BACKUP_COUNT = int(os.getenv('LOG_BACKUP_COUNT', 5))

    # Error handling specific settings
    # Set to True to mask sensitive details in error responses for production
    MASK_SENSITIVE_ERROR_DETAILS = os.getenv('MASK_SENSITIVE_ERROR_DETAILS', 'True').lower() == 'true'

    # Mapping of custom error codes to HTTP status codes (for web applications)
    HTTP_STATUS_MAP = {
        'NotFound': 404,
        'InvalidInput': 400,
        'Unauthorized': 401,
        'Forbidden': 403,
        'ServiceUnavailable': 503,
        'DatabaseError': 500,
        'ExternalServiceError': 502,
        'ConflictError': 409,
        # Default for unhandled custom errors
        'ApplicationError': 500,
        # Default for unexpected system errors
        'UnhandledError': 500
    }

# Instantiate config for easy import
app_config = Config()

Explanation:

  • Environment Variables: Uses os.getenv for flexible configuration based on deployment environment.
  • Logging Settings: Defines parameters for log level, file path, size rotation, and backup count.
  • Sensitive Data Masking: A crucial setting (MASK_SENSITIVE_ERROR_DETAILS) to control whether internal error details are exposed in public-facing error responses.
  • HTTP Status Map: Provides a mapping from custom exception names to standard HTTP status codes, essential for API consistency.

3.2. Custom Exception Classes (exceptions.py)

Define a hierarchy of custom exceptions for specific error scenarios.


# exceptions.py

from typing import Dict, Any, Optional

class ApplicationError(Exception):
    """
    Base exception class for all custom application-specific errors.
    All other custom exceptions should inherit from this class.
    """
    def __init__(self, message: str, code: Optional[str] = None, details: Optional[Dict[str, Any]] = None):
        super().__init__(message)
        self.message = message
        self.code = code if code else self.__class__.__name__ # Default code to class name
        self.details = details if details is not None else {}

    def to_dict(self) -> Dict[str, Any]:
        """Converts the exception to a dictionary for standardized error responses."""
        return {
            "code": self.code,
            "message": self.message,
            "details": self.details
        }

class NotFoundError(ApplicationError):
    """Error raised when a requested resource is not found."""
    def __init__(self, resource_name: str = "Resource", identifier: Optional[Any] = None):
        message = f"{resource_name} not found."
        if identifier:
            message += f" Identifier: {identifier}"
        super().__init__(message, code="NotFound", details={"resource": resource_name, "identifier": identifier})

class InvalidInputError(ApplicationError):
    """Error raised when input data is invalid (e.g., validation failure)."""
    def __init__(self, message: str = "Invalid input provided.", field_errors: Optional[Dict[str, str]] = None):
        details = {"field_errors": field_errors} if field_errors else {}
        super().__init__(message, code="InvalidInput", details=details)

class UnauthorizedError(ApplicationError):
    """Error raised when authentication fails or is missing."""
    def __init__(self, message: str = "Authentication required or failed."):
        super().__init__(message, code="Unauthorized")

class ForbiddenError(ApplicationError):
    """Error raised when a user is authenticated but lacks necessary permissions."""
    def __init__(self, message: str = "Permission denied."):
        super().__init__(message, code="Forbidden")

class DatabaseError(ApplicationError):
    """Error raised for issues interacting with the database."""
    def __init__(self, message: str = "A database operation failed.", original_exception: Optional[Exception] = None):
        details = {"original_error": str(original_exception)} if original_exception else {}
        super().__init__(message, code="DatabaseError", details=details)

class ExternalServiceError(ApplicationError):
    """Error raised when an external service call fails."""
    def __init__(self, service_name: str, message: str = "External service failed.", status_code: Optional[int] = None, response_body: Optional[Any] = None):
        details = {"service": service_name}
        if status_code:
            details["status_code"] = status_code
        if response_body:
            details["response_body"] = str(response_body) # Convert to string to avoid complex serialization
        super().__init__(message, code="ExternalServiceError", details=details)

class ConflictError(ApplicationError):
    """Error raised when there's a conflict, e.g., trying to create a resource that already exists."""
    def __init__(self, message: str = "Resource conflict.", conflict_field: Optional[str] = None):
        details = {"conflict_field": conflict_field} if conflict_field else {}
        super().__init__(message, code="ConflictError", details=details)

Explanation:

  • ApplicationError: The base class for all custom errors. It includes message, code, and details for rich error information. to_dict() provides a standardized output format.
  • Specific Error Classes: Examples like NotFoundError, InvalidInputError, UnauthorizedError, DatabaseError, etc., provide semantic meaning to errors, making code more readable and easier to debug. Each can accept specific parameters relevant to its context (e.g., resource_name for NotFoundError, field_errors for InvalidInputError).

3.3. Centralized Logger Configuration (logger_config.py)

Set up a robust logging system with file rotation and console output.


# logger_config.py

import logging
import logging.handlers
import sys
from config import app_config

class CustomFormatter(logging.Formatter):
    """
    Custom formatter to include process ID and thread ID,
    and handle stack traces for exceptions.
    """
    FORMAT = "[%(asctime)s][%(levelname)s][%(process)d:%(thread)d][%(name)s][%(filename)s:%(lineno)d] - %(message)s"
    DATE_FORMAT = "%Y-%m-%d %H:%M:%S"

    def format(self, record):
        log_fmt = self.FORMAT
        formatter = logging.Formatter(log_fmt, self.DATE_FORMAT)
        return formatter.format(record)

def setup_logging():
    """
    Configures the application-wide logging system.
    Sets up console and file handlers with rotation.
    """
    # Get the root logger
    logger = logging.getLogger()
    logger.setLevel(app_config.LOG_LEVEL)

    # Prevent adding multiple handlers if setup_logging is called multiple times
    if not logger.handlers:
        # Create formatter
        formatter = CustomFormatter()

        # Console Handler
        console_handler = logging.StreamHandler(sys.stdout)
        console_handler.setFormatter(formatter)
        logger.addHandler(console_handler)

        # File Handler with rotation
        file_handler = logging.handlers.RotatingFileHandler(
            app_config.LOG_FILE_PATH,
            maxBytes=app_config.LOG_MAX_BYTES,
            backupCount=app_config.LOG_BACKUP_COUNT,
            encoding='utf-8'
        )
        file_handler.setFormatter(formatter)
        logger.addHandler(file_handler)

    # Set specific log levels for noisy libraries if needed
    logging.getLogger('urllib3').setLevel(logging.WARNING)
    logging.getLogger('requests').setLevel(logging.WARNING)
    logging.getLogger('sqlalchemy').setLevel(logging.WARNING)

    return logger

# Initialize the logger
logger = setup_logging()

Explanation:

  • CustomFormatter: Ensures consistent log message formatting, including timestamp, log level, process/thread IDs, module, line number, and the message itself.
  • setup_logging():

* Retrieves the root logger and sets its level based on app_config.LOG_LEVEL.

* Adds a StreamHandler to output logs to the console (sys.stdout).

* Adds a RotatingFileHandler to write logs to a file. This handler automatically rotates log files when they reach a certain size (maxBytes) and keeps a specified number of backups (backupCount).

* Prevents duplicate handlers if setup_logging() is called multiple times.

* Optionally sets higher log levels for known noisy third-party libraries.

  • logger = setup_logging(): Initializes the logger immediately upon import, making it ready for use across the application.

3.4. Error Handling Decorator/Utility (error_handler.py)

This component provides a decorator to wrap functions and automatically catch, log, and handle exceptions. This is particularly useful for API endpoints or critical business logic.


# error_handler.py

import sys
import traceback
from functools import wraps
from typing import Callable, Any, Dict, Tuple

from logger_config import logger
from exceptions import ApplicationError, NotFoundError, InvalidInputError, UnauthorizedError, ForbiddenError, \
    DatabaseError, ExternalServiceError, ConflictError
from config import app_config

def handle_errors(func: Callable[..., Any]) -> Callable[..., Any]:
    """
    A decorator to centralize error handling for functions (e.g., API endpoints).
    It catches exceptions, logs them, and returns a standardized error response.
    """
    @wraps(func)
    def wrapper(*args: Any, **kwargs: Any) -> Tuple[Dict[str, Any], int]:
        try:
            result = func(*args, **kwargs)
            return result
        except ApplicationError as e:
            # Handle custom application-specific errors
            log_level = logger.warning if isinstance(e, (NotFoundError, InvalidInputError, ConflictError)) else logger.error
            log_level(f"Application Error caught: {e.code} - {e.message}", exc_info=True)

            status_code = app_config.HTTP_STATUS_MAP.get(e.code, app_config.HTTP_STATUS_MAP['ApplicationError'])
            
            # Mask sensitive details for production if configured
            if app_config.MASK_SENSITIVE_ERROR_DETAILS and status_code >= 500:
                response_message = "An internal server error occurred."
                response_details = {}
            else:
                response_message = e.message
                response_details = e.details

            error_response = {
                "status": "error",
                "code": e.code,
                "message": response_message,
                "details": response_details
            }
            return error_response, status_code

        except Exception as e:
            # Handle unexpected system errors
            error_id = generate_error_id() # Unique ID for tracing
            logger.exception(f"Unhandled System Error (ID: {error_id}) caught: {e}")

            # Always mask details for unexpected system errors in production
            response_message = "An unexpected error occurred. Please try again later."
            if app_config
gemini Output

Error Handling System: Comprehensive Deliverable

Project Title: Error Handling System

Workflow Step: 3 of 3 - Review and Document

Date: October 26, 2023

Prepared For: [Customer Name/Team]

Prepared By: PantheraHive AI Assistant


1. Executive Summary

This document provides a comprehensive overview and detailed documentation of the proposed Error Handling System. Designed to enhance system stability, improve user experience, and streamline operational efficiency, this system establishes a robust framework for detecting, logging, notifying, and resolving errors across your applications and infrastructure. It outlines core principles, architectural components, implementation guidelines, and operational procedures, ensuring a proactive and systematic approach to managing unexpected events.

2. Introduction to the Error Handling System

An effective Error Handling System is crucial for the reliability and maintainability of any software application or service. It moves beyond basic "try-catch" blocks to provide a structured, centralized, and actionable mechanism for dealing with exceptions, faults, and unexpected behaviors.

The primary objectives of this system are to:

  • Improve System Reliability: Minimize downtime and ensure continuous service availability.
  • Enhance User Experience: Prevent application crashes and provide clear, actionable feedback to users when errors occur.
  • Accelerate Problem Resolution: Provide developers and operations teams with timely, detailed, and contextual information to diagnose and fix issues quickly.
  • Gain Operational Insights: Collect data on error patterns, frequency, and impact to inform future development and resource allocation.
  • Maintain Data Integrity: Ensure that errors do not lead to corrupted data states.

3. Core Principles of the Error Handling System

The design and implementation of this Error Handling System are guided by the following principles:

  • Centralization: All errors, regardless of their origin (frontend, backend, infrastructure), are processed and stored in a unified manner.
  • Contextual Information: Every error log must include sufficient context (user, request, environment, stack trace, data values) to facilitate rapid diagnosis.
  • Actionability: Error notifications and reports should directly lead to specific actions by the relevant teams.
  • Graceful Degradation: The system should attempt to recover or degrade gracefully rather than crashing entirely when non-fatal errors occur.
  • Security: Sensitive information must be appropriately scrubbed or masked from error logs and notifications.
  • Performance: The error handling mechanism itself should have minimal impact on application performance.
  • Observability: The system should be easily monitorable, providing clear dashboards and alerts.
  • Standardization: Use consistent error codes, messages, and logging formats across all components.

4. Key Components and Architecture

The Error Handling System is composed of several interconnected components designed to cover the entire lifecycle of an error.

4.1. Error Detection Mechanisms

  • Application-Level Exception Handling:

* Structured Try-Catch Blocks: Enforce explicit handling of anticipated exceptions at critical points in the code.

* Global Exception Handlers: Catch unhandled exceptions at the application or framework level (e.g., middleware in web frameworks, global handlers in desktop apps).

* Custom Error Types: Define specific error classes for domain-specific business logic failures.

  • Infrastructure-Level Monitoring:

* System Logs: Monitor operating system, web server (Nginx/Apache), and database logs for anomalies.

* Resource Monitoring: Track CPU, memory, disk I/O, network usage to detect performance bottlenecks that might manifest as errors.

* Health Checks: Implement regular probes for service availability and responsiveness.

4.2. Error Logging & Storage

  • Centralized Logging Service:

* Purpose: Aggregate logs from all services and applications into a single, searchable repository.

* Recommended Technologies: ELK Stack (Elasticsearch, Logstash, Kibana), Splunk, Datadog, AWS CloudWatch Logs, Google Cloud Logging.

* Data Structure: Standardized JSON format for logs, including:

* timestamp: UTC time of error occurrence.

* level: (e.g., DEBUG, INFO, WARNING, ERROR, CRITICAL).

* service_name: Name of the application/microservice.

* component: Specific module or function.

* error_code: Standardized alphanumeric code.

* message: Human-readable error description.

* stack_trace: Full call stack.

* request_id: Unique identifier for the user request/transaction.

* user_id: Identifier for the affected user (if applicable, anonymized if sensitive).

* environment: (e.g., development, staging, production).

* host_ip, container_id: Infrastructure details.

* metadata: Additional contextual key-value pairs (e.g., request parameters, database query, external API response).

  • Log Retention Policy: Define appropriate retention periods based on compliance, debugging needs, and storage costs.

4.3. Error Notification & Alerting

  • Real-time Alerts: Trigger immediate notifications for critical errors.

* Channels: Slack/Microsoft Teams, PagerDuty, Opsgenie, Email, SMS.

* Thresholds: Configure alerts based on:

* Error Level: Trigger for all CRITICAL errors, specific ERROR types.

* Frequency: N errors of type X within Y minutes.

* Impact: Errors affecting a certain percentage of users or requests.

  • Summary Reports: Daily/weekly digests of less critical or frequently occurring errors.

* Channels: Email reports, dashboard summaries.

4.4. Error Reporting & Analytics

  • Dashboards: Visual representation of error trends, frequency, and distribution.

* Key Metrics: Error rate over time, top N errors, services with most errors, mean time to acknowledge (MTTA), mean time to resolve (MTTR).

* Tools: Kibana, Grafana, custom dashboards built on log data.

  • Root Cause Analysis (RCA) Tools: Capabilities within the logging platform to drill down into specific error instances, filter, and correlate logs.

4.5. Error Resolution & Recovery

  • Automated Recovery: Implement mechanisms for self-healing where possible (e.g., retry mechanisms for transient network errors, circuit breakers for failing services, automatic restarts of crashed containers).
  • Manual Incident Response: Define clear workflows for teams to investigate, diagnose, and resolve errors identified through alerts.
  • Post-Mortem Analysis: Document critical incidents to identify root causes, implement preventive measures, and improve future response.

5. Implementation Guidelines

5.1. Standardized Error Codes and Messages

  • Adopt a consistent error coding scheme:

* Example: [SERVICE]-[TYPE]-[CODE] (e.g., AUTH-401-001 for Authentication Failed - Invalid Credentials).

* Categorize errors (e.g., APP for application logic, DB for database, EXT for external service, SYS for system/infrastructure).

  • Craft clear, concise, and actionable error messages:

* For internal logs: Detailed technical information.

* For external users: User-friendly messages that guide them or suggest next steps, avoiding technical jargon. Provide a reference ID for support.

5.2. Contextual Information Enrichment

  • Mandatory Context: Ensure all error logging functions automatically capture timestamp, level, service_name, environment, and stack_trace.
  • Runtime Context: Encourage developers to add relevant contextual data such as:

* User ID (anonymized/hashed if PII)

* Request parameters (sanitized)

* Session data

* Relevant variable values leading up to the error

* External API call details

5.3. Logging Levels Discipline

  • CRITICAL: System is down or severely impaired. Immediate human intervention required.
  • ERROR: An issue occurred that prevented a specific operation from completing successfully, but the system might still be functional. Requires investigation.
  • WARNING: Potential issue or deviation from expected behavior that might lead to an error later. Requires monitoring.
  • INFO: General operational messages, indicating progress or significant events.
  • DEBUG: Detailed information primarily for development and troubleshooting.

5.4. Security Considerations

  • PII/Sensitive Data Masking: Implement automatic masking or removal of Personally Identifiable Information (PII), financial data, or other sensitive information from logs before storage.
  • Access Control: Restrict access to error logs and dashboards based on roles and responsibilities.
  • Encryption: Encrypt logs at rest and in transit.

5.5. Performance Considerations

  • Asynchronous Logging: Implement logging asynchronously to prevent it from blocking application threads.
  • Batching: Batch log messages before sending them to the centralized logging service to reduce I/O overhead.
  • Sampling (for DEBUG/INFO): In high-volume systems, consider sampling lower-level logs (DEBUG/INFO) in production to reduce log volume, while always logging ERROR and CRITICAL events.

6. Operational Procedures

6.1. Monitoring and Alerting Configuration

  • Review and Refine Alerts: Regularly review alert thresholds and notification channels. Adjust based on system behavior and incident frequency to minimize alert fatigue.
  • Dashboard Maintenance: Keep error dashboards updated and relevant to current operational needs.

6.2. Incident Response Workflow

  • Tiered Response: Define clear escalation paths (e.g., L1 support -> L2 engineering -> L3 architecture).
  • Runbooks: Develop detailed runbooks for common error types, outlining steps for diagnosis, mitigation, and resolution.
  • Communication Protocols: Establish clear internal and external communication plans during incidents.

6.3. Regular Reviews and Maintenance

  • Error Review Meetings: Conduct weekly/bi-weekly meetings with development and operations teams to review top errors, discuss recurring issues, and prioritize fixes.
  • Log Volume Management: Periodically assess log volume and adjust retention policies or logging levels if costs become prohibitive or performance is impacted.
  • System Health Checks: Regularly verify the health and performance of the logging and monitoring infrastructure itself.

7. Benefits of the System

Implementing this comprehensive Error Handling System will yield significant benefits:

  • Increased System Stability and Uptime: Proactive detection and faster resolution reduce service disruptions.
  • Improved Developer Productivity: Developers spend less time reproducing issues and more time building new features, thanks to rich contextual error data.
  • Enhanced Customer Satisfaction: Fewer visible errors and quicker problem resolution lead to a more reliable and trustworthy user experience.
  • Better Resource Utilization: Insights from error analytics help identify and address architectural weaknesses or resource bottlenecks.
  • Reduced Operational Costs: Automation and streamlined workflows minimize manual effort in troubleshooting.
  • Data-Driven Decision Making: Error trends and metrics provide valuable input for product development and infrastructure planning.

8. Next Steps & Recommendations

To move forward with the successful implementation and adoption of this Error Handling System, we recommend the following actionable steps:

  1. Technology Selection Review:

* Action: Finalize the choice of centralized logging platform (e.g., ELK, Splunk, Datadog) and alerting tools (e.g., PagerDuty, Slack integration).

* Owner: [Infrastructure/DevOps Lead]

* Timeline: Within 2 weeks.

  1. Standardized Error Code Definition:

* Action: Develop and publish a comprehensive list of standardized error codes and associated messages for all services.

* Owner: [Architecture/Development Lead]

* Timeline: Within 3 weeks.

  1. Core Logging Library/Module Development:

* Action: Create a shared logging library or module that encapsulates the error logging logic, ensuring consistent format, context enrichment, and asynchronous behavior.

* Owner: [Development Lead]

* Timeline: Within 4 weeks.

  1. Pilot Service Integration:

* Action: Select a critical, but manageable, service or application for initial integration of the new error handling system.

* Owner: [Project Manager, Service Owner]

* Timeline: Within 6 weeks.

  1. Alerting & Dashboard Configuration:

* Action: Configure initial critical alerts and create essential error monitoring dashboards for the pilot service.

* Owner: [Operations/DevOps Lead]

* Timeline: Concurrent with pilot integration.

  1. Team Training & Documentation:

* Action: Conduct training sessions for development and operations teams on how to use the new system, interpret logs, and respond to alerts. Document best practices.

* Owner: [Training Lead, Documentation Specialist]

* Timeline: Ongoing, starting after pilot.

  1. Phased Rollout Plan:

* Action: Develop a comprehensive plan for rolling out the error handling system across all remaining applications and services.

* Owner: [Project Manager]

* Timeline: After successful pilot completion.


This document serves as a foundational blueprint for your Error Handling System. PantheraHive is committed to supporting you through each phase of implementation to ensure a robust, efficient, and highly effective system.

error_handling_system.txt
Download source file
Copy all content
Full output as text
Download ZIP
IDE-ready project ZIP
Copy share link
Permanent URL for this run
Get Embed Code
Embed this result on any website
Print / Save PDF
Use browser print dialog
\n\n\n"); var hasSrcMain=Object.keys(extracted).some(function(k){return k.indexOf("src/main")>=0;}); if(!hasSrcMain) zip.file(folder+"src/main."+ext,"import React from 'react'\nimport ReactDOM from 'react-dom/client'\nimport App from './App'\nimport './index.css'\n\nReactDOM.createRoot(document.getElementById('root')!).render(\n \n \n \n)\n"); var hasSrcApp=Object.keys(extracted).some(function(k){return k==="src/App."+ext||k==="App."+ext;}); if(!hasSrcApp) zip.file(folder+"src/App."+ext,"import React from 'react'\nimport './App.css'\n\nfunction App(){\n return(\n
\n
\n

"+slugTitle(pn)+"

\n

Built with PantheraHive BOS

\n
\n
\n )\n}\nexport default App\n"); zip.file(folder+"src/index.css","*{margin:0;padding:0;box-sizing:border-box}\nbody{font-family:system-ui,-apple-system,sans-serif;background:#f0f2f5;color:#1a1a2e}\n.app{min-height:100vh;display:flex;flex-direction:column}\n.app-header{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;padding:40px}\nh1{font-size:2.5rem;font-weight:700}\n"); zip.file(folder+"src/App.css",""); zip.file(folder+"src/components/.gitkeep",""); zip.file(folder+"src/pages/.gitkeep",""); zip.file(folder+"src/hooks/.gitkeep",""); Object.keys(extracted).forEach(function(p){ var fp=p.startsWith("src/")?p:"src/"+p; zip.file(folder+fp,extracted[p]); }); zip.file(folder+"README.md","# "+slugTitle(pn)+"\n\nGenerated by PantheraHive BOS.\n\n## Setup\n\`\`\`bash\nnpm install\nnpm run dev\n\`\`\`\n\n## Build\n\`\`\`bash\nnpm run build\n\`\`\`\n\n## Open in IDE\nOpen the project folder in VS Code or WebStorm.\n"); zip.file(folder+".gitignore","node_modules/\ndist/\n.env\n.DS_Store\n*.local\n"); } /* --- Vue (Vite + Composition API + TypeScript) --- */ function buildVue(zip,folder,app,code,panelTxt){ var pn=pkgName(app); var C=cc(pn); var extracted=extractCode(panelTxt); zip.file(folder+"package.json",'{\n "name": "'+pn+'",\n "version": "0.0.0",\n "type": "module",\n "scripts": {\n "dev": "vite",\n "build": "vue-tsc -b && vite build",\n "preview": "vite preview"\n },\n "dependencies": {\n "vue": "^3.5.13",\n "vue-router": "^4.4.5",\n "pinia": "^2.3.0",\n "axios": "^1.7.9"\n },\n "devDependencies": {\n "@vitejs/plugin-vue": "^5.2.1",\n "typescript": "~5.7.3",\n "vite": "^6.0.5",\n "vue-tsc": "^2.2.0"\n }\n}\n'); zip.file(folder+"vite.config.ts","import { defineConfig } from 'vite'\nimport vue from '@vitejs/plugin-vue'\nimport { resolve } from 'path'\n\nexport default defineConfig({\n plugins: [vue()],\n resolve: { alias: { '@': resolve(__dirname,'src') } }\n})\n"); zip.file(folder+"tsconfig.json",'{"files":[],"references":[{"path":"./tsconfig.app.json"},{"path":"./tsconfig.node.json"}]}\n'); zip.file(folder+"tsconfig.app.json",'{\n "compilerOptions":{\n "target":"ES2020","useDefineForClassFields":true,"module":"ESNext","lib":["ES2020","DOM","DOM.Iterable"],\n "skipLibCheck":true,"moduleResolution":"bundler","allowImportingTsExtensions":true,\n "isolatedModules":true,"moduleDetection":"force","noEmit":true,"jsxImportSource":"vue",\n "strict":true,"paths":{"@/*":["./src/*"]}\n },\n "include":["src/**/*.ts","src/**/*.d.ts","src/**/*.tsx","src/**/*.vue"]\n}\n'); zip.file(folder+"env.d.ts","/// \n"); zip.file(folder+"index.html","\n\n\n \n \n "+slugTitle(pn)+"\n\n\n
\n \n\n\n"); var hasMain=Object.keys(extracted).some(function(k){return k==="src/main.ts"||k==="main.ts";}); if(!hasMain) zip.file(folder+"src/main.ts","import { createApp } from 'vue'\nimport { createPinia } from 'pinia'\nimport App from './App.vue'\nimport './assets/main.css'\n\nconst app = createApp(App)\napp.use(createPinia())\napp.mount('#app')\n"); var hasApp=Object.keys(extracted).some(function(k){return k.indexOf("App.vue")>=0;}); if(!hasApp) zip.file(folder+"src/App.vue","\n\n\n\n\n"); zip.file(folder+"src/assets/main.css","*{margin:0;padding:0;box-sizing:border-box}body{font-family:system-ui,sans-serif;background:#fff;color:#213547}\n"); zip.file(folder+"src/components/.gitkeep",""); zip.file(folder+"src/views/.gitkeep",""); zip.file(folder+"src/stores/.gitkeep",""); Object.keys(extracted).forEach(function(p){ var fp=p.startsWith("src/")?p:"src/"+p; zip.file(folder+fp,extracted[p]); }); zip.file(folder+"README.md","# "+slugTitle(pn)+"\n\nGenerated by PantheraHive BOS.\n\n## Setup\n\`\`\`bash\nnpm install\nnpm run dev\n\`\`\`\n\n## Build\n\`\`\`bash\nnpm run build\n\`\`\`\n\nOpen in VS Code or WebStorm.\n"); zip.file(folder+".gitignore","node_modules/\ndist/\n.env\n.DS_Store\n*.local\n"); } /* --- Angular (v19 standalone) --- */ function buildAngular(zip,folder,app,code,panelTxt){ var pn=pkgName(app); var C=cc(pn); var sel=pn.replace(/_/g,"-"); var extracted=extractCode(panelTxt); zip.file(folder+"package.json",'{\n "name": "'+pn+'",\n "version": "0.0.0",\n "scripts": {\n "ng": "ng",\n "start": "ng serve",\n "build": "ng build",\n "test": "ng test"\n },\n "dependencies": {\n "@angular/animations": "^19.0.0",\n "@angular/common": "^19.0.0",\n "@angular/compiler": "^19.0.0",\n "@angular/core": "^19.0.0",\n "@angular/forms": "^19.0.0",\n "@angular/platform-browser": "^19.0.0",\n "@angular/platform-browser-dynamic": "^19.0.0",\n "@angular/router": "^19.0.0",\n "rxjs": "~7.8.0",\n "tslib": "^2.3.0",\n "zone.js": "~0.15.0"\n },\n "devDependencies": {\n "@angular-devkit/build-angular": "^19.0.0",\n "@angular/cli": "^19.0.0",\n "@angular/compiler-cli": "^19.0.0",\n "typescript": "~5.6.0"\n }\n}\n'); zip.file(folder+"angular.json",'{\n "$schema": "./node_modules/@angular/cli/lib/config/schema.json",\n "version": 1,\n "newProjectRoot": "projects",\n "projects": {\n "'+pn+'": {\n "projectType": "application",\n "root": "",\n "sourceRoot": "src",\n "prefix": "app",\n "architect": {\n "build": {\n "builder": "@angular-devkit/build-angular:application",\n "options": {\n "outputPath": "dist/'+pn+'",\n "index": "src/index.html",\n "browser": "src/main.ts",\n "tsConfig": "tsconfig.app.json",\n "styles": ["src/styles.css"],\n "scripts": []\n }\n },\n "serve": {"builder":"@angular-devkit/build-angular:dev-server","configurations":{"production":{"buildTarget":"'+pn+':build:production"},"development":{"buildTarget":"'+pn+':build:development"}},"defaultConfiguration":"development"}\n }\n }\n }\n}\n'); zip.file(folder+"tsconfig.json",'{\n "compileOnSave": false,\n "compilerOptions": {"baseUrl":"./","outDir":"./dist/out-tsc","forceConsistentCasingInFileNames":true,"strict":true,"noImplicitOverride":true,"noPropertyAccessFromIndexSignature":true,"noImplicitReturns":true,"noFallthroughCasesInSwitch":true,"paths":{"@/*":["src/*"]},"skipLibCheck":true,"esModuleInterop":true,"sourceMap":true,"declaration":false,"experimentalDecorators":true,"moduleResolution":"bundler","importHelpers":true,"target":"ES2022","module":"ES2022","useDefineForClassFields":false,"lib":["ES2022","dom"]},\n "references":[{"path":"./tsconfig.app.json"}]\n}\n'); zip.file(folder+"tsconfig.app.json",'{\n "extends":"./tsconfig.json",\n "compilerOptions":{"outDir":"./dist/out-tsc","types":[]},\n "files":["src/main.ts"],\n "include":["src/**/*.d.ts"]\n}\n'); zip.file(folder+"src/index.html","\n\n\n \n "+slugTitle(pn)+"\n \n \n \n\n\n \n\n\n"); zip.file(folder+"src/main.ts","import { bootstrapApplication } from '@angular/platform-browser';\nimport { appConfig } from './app/app.config';\nimport { AppComponent } from './app/app.component';\n\nbootstrapApplication(AppComponent, appConfig)\n .catch(err => console.error(err));\n"); zip.file(folder+"src/styles.css","* { margin: 0; padding: 0; box-sizing: border-box; }\nbody { font-family: system-ui, -apple-system, sans-serif; background: #f9fafb; color: #111827; }\n"); var hasComp=Object.keys(extracted).some(function(k){return k.indexOf("app.component")>=0;}); if(!hasComp){ zip.file(folder+"src/app/app.component.ts","import { Component } from '@angular/core';\nimport { RouterOutlet } from '@angular/router';\n\n@Component({\n selector: 'app-root',\n standalone: true,\n imports: [RouterOutlet],\n templateUrl: './app.component.html',\n styleUrl: './app.component.css'\n})\nexport class AppComponent {\n title = '"+pn+"';\n}\n"); zip.file(folder+"src/app/app.component.html","
\n
\n

"+slugTitle(pn)+"

\n

Built with PantheraHive BOS

\n
\n \n
\n"); zip.file(folder+"src/app/app.component.css",".app-header{display:flex;flex-direction:column;align-items:center;justify-content:center;min-height:60vh;gap:16px}h1{font-size:2.5rem;font-weight:700;color:#6366f1}\n"); } zip.file(folder+"src/app/app.config.ts","import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';\nimport { provideRouter } from '@angular/router';\nimport { routes } from './app.routes';\n\nexport const appConfig: ApplicationConfig = {\n providers: [\n provideZoneChangeDetection({ eventCoalescing: true }),\n provideRouter(routes)\n ]\n};\n"); zip.file(folder+"src/app/app.routes.ts","import { Routes } from '@angular/router';\n\nexport const routes: Routes = [];\n"); Object.keys(extracted).forEach(function(p){ var fp=p.startsWith("src/")?p:"src/"+p; zip.file(folder+fp,extracted[p]); }); zip.file(folder+"README.md","# "+slugTitle(pn)+"\n\nGenerated by PantheraHive BOS.\n\n## Setup\n\`\`\`bash\nnpm install\nng serve\n# or: npm start\n\`\`\`\n\n## Build\n\`\`\`bash\nng build\n\`\`\`\n\nOpen in VS Code with Angular Language Service extension.\n"); zip.file(folder+".gitignore","node_modules/\ndist/\n.env\n.DS_Store\n*.local\n.angular/\n"); } /* --- Python --- */ function buildPython(zip,folder,app,code){ var title=slugTitle(app); var pn=pkgName(app); var src=code.replace(/^\`\`\`[\w]*\n?/m,"").replace(/\n?\`\`\`$/m,"").trim(); var reqMap={"numpy":"numpy","pandas":"pandas","sklearn":"scikit-learn","tensorflow":"tensorflow","torch":"torch","flask":"flask","fastapi":"fastapi","uvicorn":"uvicorn","requests":"requests","sqlalchemy":"sqlalchemy","pydantic":"pydantic","dotenv":"python-dotenv","PIL":"Pillow","cv2":"opencv-python","matplotlib":"matplotlib","seaborn":"seaborn","scipy":"scipy"}; var reqs=[]; Object.keys(reqMap).forEach(function(k){if(src.indexOf("import "+k)>=0||src.indexOf("from "+k)>=0)reqs.push(reqMap[k]);}); var reqsTxt=reqs.length?reqs.join("\n"):"# add dependencies here\n"; zip.file(folder+"main.py",src||"# "+title+"\n# Generated by PantheraHive BOS\n\nprint(title+\" loaded\")\n"); zip.file(folder+"requirements.txt",reqsTxt); zip.file(folder+".env.example","# Environment variables\n"); zip.file(folder+"README.md","# "+title+"\n\nGenerated by PantheraHive BOS.\n\n## Setup\n\`\`\`bash\npython3 -m venv .venv\nsource .venv/bin/activate\npip install -r requirements.txt\n\`\`\`\n\n## Run\n\`\`\`bash\npython main.py\n\`\`\`\n"); zip.file(folder+".gitignore",".venv/\n__pycache__/\n*.pyc\n.env\n.DS_Store\n"); } /* --- Node.js --- */ function buildNode(zip,folder,app,code){ var title=slugTitle(app); var pn=pkgName(app); var src=code.replace(/^\`\`\`[\w]*\n?/m,"").replace(/\n?\`\`\`$/m,"").trim(); var depMap={"mongoose":"^8.0.0","dotenv":"^16.4.5","axios":"^1.7.9","cors":"^2.8.5","bcryptjs":"^2.4.3","jsonwebtoken":"^9.0.2","socket.io":"^4.7.4","uuid":"^9.0.1","zod":"^3.22.4","express":"^4.18.2"}; var deps={}; Object.keys(depMap).forEach(function(k){if(src.indexOf(k)>=0)deps[k]=depMap[k];}); if(!deps["express"])deps["express"]="^4.18.2"; var pkgJson=JSON.stringify({"name":pn,"version":"1.0.0","main":"src/index.js","scripts":{"start":"node src/index.js","dev":"nodemon src/index.js"},"dependencies":deps,"devDependencies":{"nodemon":"^3.0.3"}},null,2)+"\n"; zip.file(folder+"package.json",pkgJson); var fallback="const express=require(\"express\");\nconst app=express();\napp.use(express.json());\n\napp.get(\"/\",(req,res)=>{\n res.json({message:\""+title+" API\"});\n});\n\nconst PORT=process.env.PORT||3000;\napp.listen(PORT,()=>console.log(\"Server on port \"+PORT));\n"; zip.file(folder+"src/index.js",src||fallback); zip.file(folder+".env.example","PORT=3000\n"); zip.file(folder+".gitignore","node_modules/\n.env\n.DS_Store\n"); zip.file(folder+"README.md","# "+title+"\n\nGenerated by PantheraHive BOS.\n\n## Setup\n\`\`\`bash\nnpm install\n\`\`\`\n\n## Run\n\`\`\`bash\nnpm run dev\n\`\`\`\n"); } /* --- Vanilla HTML --- */ function buildVanillaHtml(zip,folder,app,code){ var title=slugTitle(app); var isFullDoc=code.trim().toLowerCase().indexOf("=0||code.trim().toLowerCase().indexOf("=0; var indexHtml=isFullDoc?code:"\n\n\n\n\n"+title+"\n\n\n\n"+code+"\n\n\n\n"; zip.file(folder+"index.html",indexHtml); zip.file(folder+"style.css","/* "+title+" — styles */\n*{margin:0;padding:0;box-sizing:border-box}\nbody{font-family:system-ui,-apple-system,sans-serif;background:#fff;color:#1a1a2e}\n"); zip.file(folder+"script.js","/* "+title+" — scripts */\n"); zip.file(folder+"assets/.gitkeep",""); zip.file(folder+"README.md","# "+title+"\n\nGenerated by PantheraHive BOS.\n\n## Open\nDouble-click \`index.html\` in your browser.\n\nOr serve locally:\n\`\`\`bash\nnpx serve .\n# or\npython3 -m http.server 3000\n\`\`\`\n"); zip.file(folder+".gitignore",".DS_Store\nnode_modules/\n.env\n"); } /* ===== MAIN ===== */ var sc=document.createElement("script"); sc.src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"; sc.onerror=function(){ if(lbl)lbl.textContent="Download ZIP"; alert("JSZip load failed — check connection."); }; sc.onload=function(){ var zip=new JSZip(); var base=(_phFname||"output").replace(/\.[^.]+$/,""); var app=base.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")||"my_app"; var folder=app+"/"; var vc=document.getElementById("panel-content"); var panelTxt=vc?(vc.innerText||vc.textContent||""):""; var lang=detectLang(_phCode,panelTxt); if(_phIsHtml){ buildVanillaHtml(zip,folder,app,_phCode); } else if(lang==="flutter"){ buildFlutter(zip,folder,app,_phCode,panelTxt); } else if(lang==="react-native"){ buildReactNative(zip,folder,app,_phCode,panelTxt); } else if(lang==="swift"){ buildSwift(zip,folder,app,_phCode,panelTxt); } else if(lang==="kotlin"){ buildKotlin(zip,folder,app,_phCode,panelTxt); } else if(lang==="react"){ buildReact(zip,folder,app,_phCode,panelTxt); } else if(lang==="vue"){ buildVue(zip,folder,app,_phCode,panelTxt); } else if(lang==="angular"){ buildAngular(zip,folder,app,_phCode,panelTxt); } else if(lang==="python"){ buildPython(zip,folder,app,_phCode); } else if(lang==="node"){ buildNode(zip,folder,app,_phCode); } else { /* Document/content workflow */ var title=app.replace(/_/g," "); var md=_phAll||_phCode||panelTxt||"No content"; zip.file(folder+app+".md",md); var h=""+title+""; h+="

"+title+"

"; var hc=md.replace(/&/g,"&").replace(//g,">"); hc=hc.replace(/^### (.+)$/gm,"

$1

"); hc=hc.replace(/^## (.+)$/gm,"

$1

"); hc=hc.replace(/^# (.+)$/gm,"

$1

"); hc=hc.replace(/\*\*(.+?)\*\*/g,"$1"); hc=hc.replace(/\n{2,}/g,"

"); h+="

"+hc+"

Generated by PantheraHive BOS
"; zip.file(folder+app+".html",h); zip.file(folder+"README.md","# "+title+"\n\nGenerated by PantheraHive BOS.\n\nFiles:\n- "+app+".md (Markdown)\n- "+app+".html (styled HTML)\n"); } zip.generateAsync({type:"blob"}).then(function(blob){ var a=document.createElement("a"); a.href=URL.createObjectURL(blob); a.download=app+".zip"; a.click(); URL.revokeObjectURL(a.href); if(lbl)lbl.textContent="Download ZIP"; }); }; document.head.appendChild(sc); } function phShare(){navigator.clipboard.writeText(window.location.href).then(function(){var el=document.getElementById("ph-share-lbl");if(el){el.textContent="Link copied!";setTimeout(function(){el.textContent="Copy share link";},2500);}});}function phEmbed(){var runId=window.location.pathname.split("/").pop().replace(".html","");var embedUrl="https://pantherahive.com/embed/"+runId;var code='';navigator.clipboard.writeText(code).then(function(){var el=document.getElementById("ph-embed-lbl");if(el){el.textContent="Embed code copied!";setTimeout(function(){el.textContent="Get Embed Code";},2500);}});}