mrradix commited on
Commit
afc51ae
·
verified ·
1 Parent(s): a9c1f33

Update utils/error_handling.py

Browse files
Files changed (1) hide show
  1. utils/error_handling.py +40 -1
utils/error_handling.py CHANGED
@@ -113,4 +113,43 @@ def show_success(message: str):
113
  import streamlit as st
114
  st.success(message)
115
  except ImportError:
116
- print(f"SUCCESS: {message}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  import streamlit as st
114
  st.success(message)
115
  except ImportError:
116
+ print(f"SUCCESS: {message}")
117
+
118
+ def handle_exceptions(func: Callable) -> Callable:
119
+ """
120
+ General exception handler decorator
121
+
122
+ Args:
123
+ func: Function to wrap with exception handling
124
+
125
+ Returns:
126
+ Wrapped function with exception handling
127
+ """
128
+ @functools.wraps(func)
129
+ def wrapper(*args, **kwargs):
130
+ try:
131
+ return func(*args, **kwargs)
132
+ except Exception as e:
133
+ log_error(logger, f"Exception in {func.__name__}: {str(e)}")
134
+ log_error(logger, f"Traceback: {traceback.format_exc()}")
135
+ return None
136
+
137
+ return wrapper
138
+
139
+ def safe_get(dictionary: dict, key: str, default: Any = None) -> Any:
140
+ """
141
+ Safely get value from dictionary
142
+
143
+ Args:
144
+ dictionary: Dictionary to get value from
145
+ key: Key to look up
146
+ default: Default value if key not found
147
+
148
+ Returns:
149
+ Value from dictionary or default
150
+ """
151
+ try:
152
+ return dictionary.get(key, default)
153
+ except (AttributeError, TypeError):
154
+ logger.warning(f"safe_get failed for key '{key}' - dictionary is not dict-like")
155
+ return default