Skip to content

Commit

Permalink
mcb-update-actions - Improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
M-casado committed Jun 24, 2024
1 parent 3af4c3e commit 41ea3d3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
34 changes: 20 additions & 14 deletions .github/scripts/request_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,29 @@
import os
import sys

from utils.json_validation import request_validation, \
get_errors_response
from utils.json_validation import request_validation, get_errors_response

# --------- #
# Handling arguments
# --------- #
dirname = sys.argv[1]
curl_URL = sys.argv[2]

# - #
# Hardcoded values
# - #
extension = ".json"

# --------- #
# Running validations
# --------- #
error_dict = {}
# We iterate over the JSON documents to validate
validated_files = []
total_files = 0
files_with_errors = 0

# Iterate over the JSON documents to validate
for file in os.scandir(dirname):
if not file.path.endswith(extension):
continue

#!
print(f"----Validation attempt for file '{file}'")
#!

total_files += 1
validated_files.append(file.name)

request = request_validation(
data_filepath=file,
validator_url=curl_URL
Expand All @@ -40,7 +36,17 @@
)
if val_error:
error_dict[file.name] = val_error
files_with_errors += 1

# If the dictionary is not empty, fail the script returning it
summary = {
"n_total_files": total_files,
"n_files_with_errors": files_with_errors,
"error_files": error_dict,
"all_files": validated_files
}

if error_dict:
sys.exit(json.dumps(error_dict, sort_keys=True, indent=4))
sys.exit(json.dumps(summary, sort_keys=True, indent=4))
else:
print(json.dumps(summary, sort_keys=True, indent=4))
4 changes: 2 additions & 2 deletions .github/scripts/utils/json_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def get_errors_response(
if not response.status_code == requests.codes.ok:
error_message = (
f"The POST response was not successful: instead of {requests.codes.ok},"
f" the status code was '{response.status_code}' when validating file '{filename}'.\n"
f"Response content: {response.content.decode('utf-8')}"
f" the status code was '{response.status_code}' when validating file '{filename}'."
f" Response content: {response.content.decode('utf-8')}"
)
return error_message

Expand Down
10 changes: 0 additions & 10 deletions .github/workflows/json_validation_deploying_biovalidator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ jobs:
# We want to specify the JSON schemas and documents with the new
# changes. Therefore we specify the schemas at deployment level (-r)
run: |
#!
echo "--- Listing files:"
pwd
ls
ls ./schemas
#!
schemas_dir="./schemas"
node biovalidator/src/biovalidator -r "$schemas_dir/*.json" > biovalidator.log 2>&1 &
Expand Down Expand Up @@ -116,7 +110,3 @@ jobs:
# Biovalidator
url="http://localhost:3020/validate"
python3 ./.github/scripts/request_validation.py "$json_ex_dir" "$url"
#!
echo "Biovalidator log:\n"
cat biovalidator.log
#!

0 comments on commit 41ea3d3

Please sign in to comment.