MCPcopy
hub / github.com/benoitc/gunicorn / from_dict

Method from_dict

gunicorn/dirty/errors.py:34–77  ·  view source on GitHub ↗

Deserialize error from protocol transmission. Creates an error instance from a serialized dict. The returned error will be an instance of the appropriate subclass based on the error_type field, but constructed using the base DirtyError __init__ to preserve all detail

(cls, data)

Source from the content-addressed store, hash-verified

32
33 @classmethod
34 def from_dict(cls, data):
35 """Deserialize error from protocol transmission.
36
37 Creates an error instance from a serialized dict. The returned
38 error will be an instance of the appropriate subclass based on
39 the error_type field, but constructed using the base DirtyError
40 __init__ to preserve all details.
41 """
42 error_classes = {
43 "DirtyError": DirtyError,
44 "DirtyTimeoutError": DirtyTimeoutError,
45 "DirtyConnectionError": DirtyConnectionError,
46 "DirtyWorkerError": DirtyWorkerError,
47 "DirtyAppError": DirtyAppError,
48 "DirtyAppNotFoundError": DirtyAppNotFoundError,
49 "DirtyNoWorkersAvailableError": DirtyNoWorkersAvailableError,
50 "DirtyProtocolError": DirtyProtocolError,
51 }
52 error_type = data.get("error_type", "DirtyError")
53 error_class = error_classes.get(error_type, DirtyError)
54
55 # Create instance and set attributes directly to bypass
56 # subclass __init__ complexity while preserving error type
57 error = Exception.__new__(error_class)
58 error.message = data.get("message", "Unknown error")
59 error.details = data.get("details") or {}
60 Exception.__init__(error, error.message)
61
62 # Set subclass-specific attributes from details
63 if error_class == DirtyTimeoutError:
64 error.timeout = error.details.get("timeout")
65 elif error_class == DirtyConnectionError:
66 error.socket_path = error.details.get("socket_path")
67 elif error_class == DirtyWorkerError:
68 error.worker_id = error.details.get("worker_id")
69 error.traceback = error.details.get("traceback")
70 elif error_class in (DirtyAppError, DirtyAppNotFoundError):
71 error.app_path = error.details.get("app_path")
72 error.action = error.details.get("action")
73 error.traceback = error.details.get("traceback")
74 elif error_class == DirtyNoWorkersAvailableError:
75 error.app_path = error.details.get("app_path")
76
77 return error
78
79
80class DirtyTimeoutError(DirtyError):

Calls 3

__new__Method · 0.80
getMethod · 0.45
__init__Method · 0.45