@@ -175,8 +175,8 @@ def validate_photo_url(photo_url, required=False):
175175 if not parsed .netloc :
176176 raise ValueError ('Malformed photo URL: "{0}".' .format (photo_url ))
177177 return photo_url
178- except Exception :
179- raise ValueError ('Malformed photo URL: "{0}".' .format (photo_url ))
178+ except Exception as err :
179+ raise ValueError ('Malformed photo URL: "{0}".' .format (photo_url )) from err
180180
181181def validate_timestamp (timestamp , label , required = False ):
182182 """Validates the given timestamp value. Timestamps must be positive integers."""
@@ -186,8 +186,8 @@ def validate_timestamp(timestamp, label, required=False):
186186 raise ValueError ('Boolean value specified as timestamp.' )
187187 try :
188188 timestamp_int = int (timestamp )
189- except TypeError :
190- raise ValueError ('Invalid type for timestamp value: {0}.' .format (timestamp ))
189+ except TypeError as err :
190+ raise ValueError ('Invalid type for timestamp value: {0}.' .format (timestamp )) from err
191191 else :
192192 if timestamp_int != timestamp :
193193 raise ValueError ('{0} must be a numeric value and a whole number.' .format (label ))
@@ -207,8 +207,8 @@ def validate_int(value, label, low=None, high=None):
207207 raise ValueError ('Invalid type for integer value: {0}.' .format (value ))
208208 try :
209209 val_int = int (value )
210- except TypeError :
211- raise ValueError ('Invalid type for integer value: {0}.' .format (value ))
210+ except TypeError as err :
211+ raise ValueError ('Invalid type for integer value: {0}.' .format (value )) from err
212212 else :
213213 if val_int != value :
214214 # This will be True for non-numeric values like '2' and non-whole numbers like 2.5.
@@ -246,8 +246,8 @@ def validate_custom_claims(custom_claims, required=False):
246246 MAX_CLAIMS_PAYLOAD_SIZE ))
247247 try :
248248 parsed = json .loads (claims_str )
249- except Exception :
250- raise ValueError ('Failed to parse custom claims string as JSON.' )
249+ except Exception as err :
250+ raise ValueError ('Failed to parse custom claims string as JSON.' ) from err
251251
252252 if not isinstance (parsed , dict ):
253253 raise ValueError ('Custom claims must be parseable as a JSON object.' )
0 commit comments