Skip to content

Commit

Permalink
improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vemonet committed Mar 27, 2024
1 parent e07b5d6 commit fdfd9c3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
12 changes: 6 additions & 6 deletions backend/src/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ def load_cohort_dict_file(dict_path: str, cohort_id: str, user_email: str) -> Da
for i, row in df.iterrows():
# Check if required columns are present
if not row["VARIABLE NAME"] or not row["VARIABLE LABEL"] or not row["VAR TYPE"]:
errors.append(f"Row {i} is missing required data: variable_name, variable_label, or var_type")
errors.append(f"Row {i+2} is missing required data: variable_name, variable_label, or var_type")
if row["VAR TYPE"] not in ACCEPTED_DATATYPES:
errors.append(
f"Row {i} for variable {row['VARIABLE NAME']} is using a wrong datatype: {row['VAR TYPE']}. It should be one of: {', '.join(ACCEPTED_DATATYPES)}"
f"Row {i+2} for variable {row['VARIABLE NAME']} is using a wrong datatype: {row['VAR TYPE']}. It should be one of: {', '.join(ACCEPTED_DATATYPES)}"
)
# TODO: raise error when duplicate value for VARIABLE LABEL?

Expand Down Expand Up @@ -237,7 +237,7 @@ def load_cohort_dict_file(dict_path: str, cohort_id: str, user_email: str) -> Da
if column in ["categories"]:
if len(value) == 1:
errors.append(
f"Row {i+2} for variable {row['VARIABLE NAME']} has only one category {row['categories']}. It should have at least two."
f"Row {i+2} for variable {row['VARIABLE NAME']} has only one category `{row['categories'][0]['value']}`. It should have at least two."
)
continue
for index, category in enumerate(value):
Expand All @@ -257,7 +257,7 @@ def load_cohort_dict_file(dict_path: str, cohort_id: str, user_email: str) -> Da
except Exception as e:
raise HTTPException(
status_code=422,
detail=f"Error parsing the data dictionary CSV file: {e}",
detail=e,
)
return g

Expand Down Expand Up @@ -304,8 +304,6 @@ async def upload_cohort(
# Rename (backup) the existing file
os.rename(existing_file_path, backup_file_path)
break # Assuming there's only one data dictionary file per cohort
# Delete graph for this file from triplestore
delete_existing_triples(get_cohort_uri(cohort_id))

# Make sure metadata file ends with _datadictionary
metadata_filename = cohort_dictionary.filename
Expand All @@ -320,6 +318,8 @@ async def upload_cohort(

try:
g = load_cohort_dict_file(metadata_path, cohort_id, user_email)
# Delete previous graph for this file from triplestore
delete_existing_triples(get_cohort_uri(cohort_id))
publish_graph_to_endpoint(g)
except Exception as e:
os.remove(metadata_path)
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ version: "3.3"
services:

backend:
depends_on:
- db
extends:
file: docker-compose.base.yml
service: backend
Expand All @@ -13,6 +15,8 @@ services:
- 3000:80

frontend:
depends_on:
- backend
extends:
file: docker-compose.base.yml
service: frontend
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/cohorts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default function CohortsList() {
{/* TODO: add by ongoing? */}
</aside>

<div>
<div className="w-full">
<div className="mb-4">
<input
type="text"
Expand Down

0 comments on commit fdfd9c3

Please sign in to comment.