clerk-sdk 0.3.1__py3-none-any.whl → 0.3.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,3 @@
1
- import os
2
1
  import pickle
3
2
  import traceback
4
3
  from typing import Callable, Optional
@@ -17,6 +16,9 @@ def clerk_code():
17
16
  def wrapper(payload: Optional[ClerkCodePayload] = None) -> ClerkCodePayload:
18
17
  # 1. Load payload from file if not provided
19
18
  use_pickle = False
19
+ output = None
20
+ error_occurred = False
21
+ error_info = None
20
22
  if payload is None:
21
23
  use_pickle = True
22
24
  try:
@@ -28,34 +30,53 @@ def clerk_code():
28
30
  else raw_data
29
31
  )
30
32
  except Exception as e:
31
- raise RuntimeError(
32
- f"Failed to load and parse input pickle: {e}"
33
- ) from e
33
+ error_occurred = True
34
+ error_info = ApplicationException(
35
+ type_=str(type(e)),
36
+ message=f"Failed to load and parse input pickle: {e}",
37
+ traceback=traceback.format_exc(),
38
+ )
34
39
 
35
40
  # 2. Execute function
36
- try:
37
- output = func(payload)
38
- if not isinstance(output, ClerkCodePayload):
39
- raise TypeError("Function must return a ClerkCodePayload instance.")
40
- except Exception as e:
41
- # parse no standard errors into the standard Application Error
42
- output = ApplicationException(
43
- type_=str(type(e)), message=str(e), traceback=traceback.format_exc()
44
- )
41
+ if not error_occurred:
42
+ try:
43
+ output = func(payload)
44
+ if not isinstance(output, ClerkCodePayload):
45
+ raise TypeError(
46
+ "Function must return a ClerkCodePayload instance."
47
+ )
48
+ except Exception as e:
49
+ error_occurred = True
50
+ error_info = ApplicationException(
51
+ type_=str(type(e)),
52
+ message=str(e),
53
+ traceback=traceback.format_exc(),
54
+ )
45
55
 
46
56
  # 3. write to output.pkl
47
57
  try:
48
58
  if use_pickle:
49
59
  with open(output_pkl, "wb") as f:
50
- if isinstance(output, Exception):
60
+ if error_occurred:
61
+ pickle.dump(error_info, f)
62
+ elif isinstance(output, Exception):
51
63
  pickle.dump(output, f)
52
64
  else:
53
65
  pickle.dump(output.model_dump(mode="json"), f)
54
-
55
66
  except Exception as e:
56
- output = RuntimeError(f"Failed to write output pickle: {str(e)}")
57
- with open(output_pkl, "wb") as f:
58
- pickle.dump(output, f)
67
+ # If writing output.pkl fails, try to write a minimal error
68
+ try:
69
+ with open(output_pkl, "wb") as f:
70
+ pickle.dump(
71
+ ApplicationException(
72
+ type_=str(type(e)),
73
+ message=f"Failed to write output pickle: {str(e)}",
74
+ traceback=traceback.format_exc(),
75
+ ),
76
+ f,
77
+ )
78
+ except Exception:
79
+ pass # Last resort: do nothing if even this fails
59
80
 
60
81
  # 4. Raise if error or return result
61
82
  if isinstance(output, Exception):
@@ -2,12 +2,39 @@ from typing import Optional
2
2
 
3
3
 
4
4
  class AppBaseException(Exception):
5
- def __init__(self, type_: str, message: str, traceback: Optional[str] = None):
5
+ def __init__(
6
+ self,
7
+ *args,
8
+ type_: Optional[str] = None,
9
+ message: Optional[str] = None,
10
+ traceback: Optional[str] = None,
11
+ ):
12
+ # If called with positional args (e.g., during unpickling or raise("msg")),
13
+ # treat args[0] as the message.
14
+ if args and message is None:
15
+ message = args[0]
16
+
17
+ # Always call base Exception with just the message so .args == (message,)
6
18
  super().__init__(message)
7
- self.type = type_
8
- self.message = message
19
+
20
+ # Store structured fields
21
+ self.type = type_ or self.__class__.__name__
22
+ self.message = message or ""
9
23
  self.traceback = traceback
10
24
 
25
+ # (Optional) make pickling round-trip the extra fields explicitly
26
+ def __reduce__(self):
27
+ # Reconstruct with message-only (what Exception expects) and restore extras via state
28
+ return (
29
+ self.__class__,
30
+ (self.message,),
31
+ {"type": self.type, "traceback": self.traceback},
32
+ )
33
+
34
+ def __setstate__(self, state):
35
+ for k, v in state.items():
36
+ setattr(self, k, v)
37
+
11
38
 
12
39
  class ApplicationException(AppBaseException):
13
40
  pass
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clerk-sdk
3
- Version: 0.3.1
3
+ Version: 0.3.3
4
4
  Summary: Library for interacting with Clerk
5
5
  Home-page: https://github.com/F-ONE-Group/clerk_pypi
6
6
  Author: F-ONE Group
@@ -3,9 +3,9 @@ clerk/base.py,sha256=Ayb2zCQr8fqKZM_Qh3nVxVJOQkkYt-eD5VtpPXd1TLs,2669
3
3
  clerk/client.py,sha256=6nWWWjGB7a6FNUWsZRM-IoBb_mshRi6g5KX8meMiJ2E,576
4
4
  clerk/decorator/__init__.py,sha256=4VCGOFNq7pA7iJS410V_R9eWfjxP7mwxwa4thwaUTf8,39
5
5
  clerk/decorator/models.py,sha256=JWFOJuUh3F40iOL0aoNgUC9GRHU3Fcq3GOjSXA7Gwng,394
6
- clerk/decorator/task_decorator.py,sha256=ZHBNaG5zlRZ6_OaVFgVhBaowCc0Q8YgdjUPSnmOL7r4,2454
6
+ clerk/decorator/task_decorator.py,sha256=6frvOIHTtDjP2SpBMx-KLZgd1EdXHahzPm9DLSxJfjQ,3390
7
7
  clerk/exceptions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- clerk/exceptions/exceptions.py,sha256=pCG_KwJ8nwtfnljeqWXchd-qNgTeEfD8KQPXeUkN81A,331
8
+ clerk/exceptions/exceptions.py,sha256=aIrmID62HoQo0pLErfX9NR2nopTyf53BpOu4gtqAy-A,1201
9
9
  clerk/exceptions/remote_device.py,sha256=R0Vfmk8ejibEFeV29A8Vqst2YA6yxdqEX9lP5wWubgM,134
10
10
  clerk/gui_automation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  clerk/gui_automation/client.py,sha256=LqrUQtC-4pjUJYDDn_s3t073K066j_p0vf4kXLChBc0,4891
@@ -46,8 +46,8 @@ clerk/models/ui_operator.py,sha256=mKTJUFZgv7PeEt5oys28HVZxHOJsofmRQOcRpqj0dbU,2
46
46
  clerk/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
47
47
  clerk/utils/logger.py,sha256=vHbp-lUK3W3c5fhyPsp05p9LGyDHj95v8XM_XQ_FlLc,3691
48
48
  clerk/utils/save_artifact.py,sha256=94aYkYNVGcSUaSWZmdjiY6Oc-3yCKb2XWCZ56IAXQqk,1158
49
- clerk_sdk-0.3.1.dist-info/licenses/LICENSE,sha256=GTVQl3vH6ht70wJXKC0yMT8CmXKHxv_YyO_utAgm7EA,1065
50
- clerk_sdk-0.3.1.dist-info/METADATA,sha256=trPJodCcT2rWlxBIe9EBEbgoHcAbg7MvnPsHOpjm4Y0,3508
51
- clerk_sdk-0.3.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
52
- clerk_sdk-0.3.1.dist-info/top_level.txt,sha256=99eQiU6d05_-f41tmSFanfI_SIJeAdh7u9m3LNSfcv4,6
53
- clerk_sdk-0.3.1.dist-info/RECORD,,
49
+ clerk_sdk-0.3.3.dist-info/licenses/LICENSE,sha256=GTVQl3vH6ht70wJXKC0yMT8CmXKHxv_YyO_utAgm7EA,1065
50
+ clerk_sdk-0.3.3.dist-info/METADATA,sha256=nGsbiRaB7DVlftGElyUsH24-U_KRZKlj7GX0X6dghTw,3508
51
+ clerk_sdk-0.3.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
52
+ clerk_sdk-0.3.3.dist-info/top_level.txt,sha256=99eQiU6d05_-f41tmSFanfI_SIJeAdh7u9m3LNSfcv4,6
53
+ clerk_sdk-0.3.3.dist-info/RECORD,,