File size: 1,089 Bytes
599abe6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def style_error(message: str) -> str:
    """
    Style an error message with a muted red background and border.
    
    Args:
        message: The error message to style
        
    Returns:
        str: HTML-formatted error message with styling
    """
    return f"""
        <div style="padding: 1rem; 
                    border-radius: 0.5rem; 
                    background-color: #fee2e2; 
                    border: 1px solid #ef4444; 
                    margin: 1rem 0;">
            <p style="color: #dc2626; margin: 0;">🎭 {message}</p>
        </div>
    """

def format_error(error: Exception, prefix: str = "") -> str:
    """
    Format an exception into a user-friendly error message.
    
    Args:
        error: The exception to format
        prefix: Optional prefix for the error message
        
    Returns:
        str: Styled error message
    """
    error_msg = str(error)
    if len(error_msg) > 100:
        error_msg = error_msg[:100] + "..."
    
    if prefix:
        error_msg = f"{prefix}: {error_msg}"
        
    return style_error(error_msg)