Skip to content

Commit

Permalink
raise error instead print error
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Dec 13, 2024
1 parent 4d36cc5 commit db0fe23
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion psl_proof/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def load_config() -> Dict[str, Any]:
'dlp_id': 1234, # Set your own DLP ID here
'input_dir': INPUT_DIR,
'salt': 'replace-this-salt', # TODO: replace this so that we can salt in a better way
'validator_base_api_url': 'https://e3d8-169-0-170-105.ngrok-free.app' #Patrick_ToCheck
'validator_base_api_url': 'https://89fb-169-0-170-105.ngrok-free.app' #Patrick_ToCheck
}
logging.info(f"Using config: {json.dumps(config, indent=2)}")
return config
Expand Down
10 changes: 5 additions & 5 deletions psl_proof/proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def generate(self) -> ProofResponse:
is_data_authentic = verify_result.is_valid
proof_failed_reason = verify_result.error_text
else :
proof_failed_reason = "Data is not authentic"
proof_failed_reason = "The provided data could not be verified as authentic."

cargo_data = CargoData(
source_data = source_data,
Expand All @@ -86,7 +86,7 @@ def generate(self) -> ProofResponse:

current_datetime = datetime.now().isoformat()
if not is_data_authentic: #short circuit so we don't waste analysis
print(f"Not authentic: {proof_failed_reason}")
print(f"Validation proof failed: {proof_failed_reason}")
self.proof_response.score = 0.0
self.proof_response.uniqueness = 0.0
self.proof_response.quality = 0.0
Expand Down Expand Up @@ -176,7 +176,7 @@ def get_source_data(input_data: Dict[str, Any]) -> SourceData:

revision = input_data.get('revision', '')
if (revision and revision != "01.01"):
print(f"Invalid Revision: {revision}")
raise RuntimeError(f"Invalid Revision: {revision}")

submission_date = datetime.now()
#print(f"submission_date: {submission_date}")
Expand All @@ -187,7 +187,7 @@ def get_source_data(input_data: Dict[str, Any]) -> SourceData:
if input_source_value == 'TELEGRAM':
input_source = DataSource.telegram
else:
print(f"Unmapped data source: {input_source_value}")
raise RuntimeError(f"Unmapped data source: {input_source_value}")

submission_token = input_data.get('submission_token', '')

Expand Down Expand Up @@ -224,7 +224,7 @@ def get_source_data(input_data: Dict[str, Any]) -> SourceData:
source_chat
)
else:
print(f"Unhandled data source: {input_source}")
raise RuntimeError(f"Unhandled data source: {input_source}")
source_chats.append(
source_chat
)
Expand Down
10 changes: 5 additions & 5 deletions psl_proof/utils/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ def get_historical_chats(

return chat_histories
except ValueError as e:
print("Error parsing JSON response:", e)
RuntimeError("Error parsing JSON response:", e)
return None
else:
print(f"Validation failed. Status code: {response.status_code}, Response: {response.text}")
RuntimeError(f"Validation failed. Status code: {response.status_code}, Response: {response.text}")
return None

except requests.exceptions.RequestException as e:
print("An error occurred:", e)
RuntimeError("get_historical_chats:", e)
return None


Expand All @@ -89,8 +89,8 @@ def submit_data(
response = requests.post(url, json=payload, headers=headers)

if response.status_code != 200:
print(f"Submission failed. Status code: {response.status_code}, Response: {response.text}")
RuntimeError(f"Submission failed. Status code: {response.status_code}, Response: {response.text}")


except requests.exceptions.RequestException as e:
print("An error occurred:", e)
RuntimeError("submit_data:", e)
2 changes: 1 addition & 1 deletion psl_proof/utils/validate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_uniqueness_score(

time_in_seconds = (chat_ended_on - historical_chat_ended_on).total_seconds()
time_in_hours = int(time_in_seconds // 3600)
if time_in_hours < 12: # more than 12 Hours..
if time_in_hours < 12: # within 12 Hours..
return 0.0

# If no matching source_chat_id is found, return 1
Expand Down
2 changes: 2 additions & 0 deletions psl_proof/utils/validation_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ def get_validation_api_url(
api_path: str
) -> str:
base_url = config['validator_base_api_url']
if not base_url:
RuntimeError("validator_base_api_url: is not specified.")
url = f"{base_url}/{api_path}"
print(f"Connected: {url}")
return url
10 changes: 5 additions & 5 deletions psl_proof/utils/verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def verify_token(config: Dict[str, Any], source_data: SourceData) -> Optional[Ve
)
return result
except ValueError as e:
print("Error parsing JSON response:", e) # Replace with logging in production
return None
print("Error parsing JSON response:", e)
RuntimeError("Error parsing JSON response:", e) # Replace with logging in production
else:
print(f"verify_token failed. Status code: {response.status_code}, Response: {response.text}") # Replace with logging
return None
RuntimeError(f"verify_token failed. Status code: {response.status_code}, Response: {response.text}") # Replace with logging

except requests.exceptions.RequestException as e:
print("An error occurred:", e) # Replace with logging
return None
print("verify_token:", e) # Replace with logging
RuntimeError("verify_token:", e) # Replace with logging

0 comments on commit db0fe23

Please sign in to comment.