Coverage for mindsdb / integrations / utilities / utils.py: 28%
23 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-21 00:36 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-21 00:36 +0000
1from typing import Any
3import sys
6def format_exception_error(exception):
7 try:
8 exception_type, _exception_object, exception_traceback = sys.exc_info()
9 filename = exception_traceback.tb_frame.f_code.co_filename
10 line_number = exception_traceback.tb_lineno
11 error_message = f"{exception_type.__name__}: {exception}, raised at: {filename}#{line_number}"
12 except Exception:
13 error_message = str(exception)
14 return error_message
17def dict_to_yaml(d, indent=0):
18 yaml_str = ""
19 for k, v in d.items():
20 yaml_str += " " * indent + str(k) + ": "
21 if isinstance(v, dict):
22 yaml_str += "\n" + dict_to_yaml(v, indent + 2)
23 else:
24 yaml_str += str(v) + "\n"
25 return yaml_str
28# Mocks won't always have 'name' attribute.
29def get_class_name(instance: Any, default: str = "unknown"):
30 if hasattr(instance.__class__, "name"): 30 ↛ 32line 30 didn't jump to line 32 because the condition on line 30 was always true
31 return instance.__class__.name
32 return default