MCPcopy Create free account
hub / github.com/modelscope/ms-agent / enhance_error

Function enhance_error

ms_agent/utils/utils.py:46–68  ·  view source on GitHub ↗
(e, prefix: str = '')

Source from the content-addressed store, hash-verified

44
45
46def enhance_error(e, prefix: str = ''):
47 # Get the original exception type
48 exc_type = type(e)
49
50 # Special handling for ExceptionGroup
51 if exc_type.__name__ == 'ExceptionGroup':
52 # Recursively enhance each sub-exception
53 new_msg = f'{prefix}: {e}'
54 new_exceptions = [enhance_error(exc, prefix) for exc in e.exceptions]
55 # Note: ExceptionGroup requires a list of exceptions
56 new_exc = BuiltInExceptionGroup(new_msg, new_exceptions)
57 return new_exc
58
59 # For other exceptions: attempt to construct a new one, using only args[0] (the message part)
60 try:
61 # Most exception types support exc("new message")
62 new_exc = exc_type(f'{prefix}: {e}')
63 new_exc.__cause__ = e.__cause__
64 new_exc.__context__ = e.__context__
65 return new_exc
66 except Exception:
67 # Construction failed; fall back to a generic exception
68 return RuntimeError(f'{prefix}: {e}')
69
70
71def assert_package_exist(package, message: Optional[str] = None):

Callers 2

get_toolsMethod · 0.90
connectMethod · 0.90

Calls 1

Tested by

no test coverage detected