@@ -78,7 +78,7 @@ def _normalize_kas_url(self, url: str) -> str:
7878 # Parse the URL
7979 parsed = urlparse (url )
8080 except Exception as e :
81- raise SDKException (f"error trying to parse URL [{ url } ]" , e )
81+ raise SDKException (f"error trying to parse URL [{ url } ]: { e } " ) from e
8282
8383 # Check if we have a host or if this is likely a hostname:port combination
8484 if parsed .hostname is None :
@@ -100,10 +100,10 @@ def _handle_missing_scheme(self, url: str) -> str:
100100 try :
101101 port = int (port_str )
102102 return f"{ scheme } ://{ host } :{ port } "
103- except ValueError :
103+ except ValueError as err :
104104 raise SDKException (
105105 f"error trying to create URL for host and port [{ url } ]"
106- )
106+ ) from err
107107 else :
108108 # Hostname with or without path, add default port
109109 if "/" in url :
@@ -116,7 +116,7 @@ def _handle_missing_scheme(self, url: str) -> str:
116116 except Exception as e :
117117 raise SDKException (
118118 f"error trying to create URL for host and port [{ url } ]" , e
119- )
119+ ) from e
120120
121121 def _handle_existing_scheme (self , parsed ) -> str :
122122 """Handle URLs with existing scheme by normalizing protocol and port."""
@@ -138,7 +138,7 @@ def _handle_existing_scheme(self, parsed) -> str:
138138 logging .debug (f"normalized url [{ parsed .geturl ()} ] to [{ normalized_url } ]" )
139139 return normalized_url
140140 except Exception as e :
141- raise SDKException ("error creating KAS address" , e )
141+ raise SDKException (f "error creating KAS address: { e } " ) from e
142142
143143 def _get_wrapped_key_base64 (self , key_access ):
144144 """
@@ -483,7 +483,7 @@ def _get_public_key_with_connect_rpc(self, kas_info):
483483 f"Connect RPC public key request failed: { type (e ).__name__ } : { e } "
484484 )
485485 logging .error (f"Full traceback: { error_details } " )
486- raise SDKException (f"Connect RPC public key request failed: { e } " )
486+ raise SDKException (f"Connect RPC public key request failed: { e } " ) from e
487487
488488 def _normalize_session_key_type (self , session_key_type ):
489489 """
@@ -608,7 +608,7 @@ def _parse_and_decrypt_response(self, response):
608608 except Exception as e :
609609 logging .error (f"Failed to parse JSON response: { e } " )
610610 logging .error (f"Raw response content: { response .content } " )
611- raise SDKException (f"Invalid JSON response from KAS: { e } " )
611+ raise SDKException (f"Invalid JSON response from KAS: { e } " ) from e
612612
613613 entity_wrapped_key = response_data .get ("entityWrappedKey" )
614614 if not entity_wrapped_key :
@@ -702,7 +702,7 @@ def _unwrap_with_connect_rpc(
702702
703703 except Exception as e :
704704 logging .error (f"Connect RPC rewrap failed: { e } " )
705- raise SDKException (f"Connect RPC rewrap failed: { e } " )
705+ raise SDKException (f"Connect RPC rewrap failed: { e } " ) from e
706706
707707 def get_key_cache (self ) -> KASKeyCache :
708708 """Returns the KAS key cache used for storing and retrieving encryption keys."""
0 commit comments