Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Human readable exceptions messages #170

Merged
merged 4 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cads_processing_api_service/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def authenticate_user(
raise exceptions.PermissionDenied(
status_code=response.status_code,
title=response.json()["title"],
detail="operation not allowed",
)
response.raise_for_status()
user: dict[str, Any] = response.json()
Expand All @@ -144,7 +145,9 @@ def verify_permission(user_uid: str, job: cads_broker.SystemRequest) -> None:
Raised if the user has no permission to interact with the job.
"""
if job.user_uid != user_uid:
raise exceptions.PermissionDenied()
raise exceptions.PermissionDenied(
detail="operation not allowed",
)


@cachetools.cached(
Expand Down Expand Up @@ -179,6 +182,7 @@ def get_accepted_licences(auth_header: tuple[str, str]) -> set[tuple[str, int]]:
raise exceptions.PermissionDenied(
status_code=response.status_code,
title=response.json()["title"],
detail="operation not allowed",
)
response.raise_for_status()
licences = response.json()["licences"]
Expand Down Expand Up @@ -216,6 +220,7 @@ def check_licences(
raise exceptions.PermissionDenied(
title="required licences not accepted",
detail=(
"required licences not accepted; "
"please accept the following licences to proceed: "
f"{missing_licences_detail}"
),
Expand Down
4 changes: 3 additions & 1 deletion cads_processing_api_service/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,9 @@ def get_job(
if qos:
job_qos_info = utils.collect_job_qos_info(job, compute_session)
if job.portal not in portals:
raise ogc_api_processes_fastapi.exceptions.NoSuchJob()
raise ogc_api_processes_fastapi.exceptions.NoSuchJob(
detail=f"job {job_id} not found"
)
auth.verify_permission(user_uid, job)
kwargs = {}
if request:
Expand Down
4 changes: 2 additions & 2 deletions cads_processing_api_service/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def format_exception_content(
instance=instance,
trace_id=structlog.contextvars.get_contextvars().get("trace_id", "unset"),
traceback=exc.traceback,
).dict(exclude_none=True)
).model_dump(exclude_none=True)

return exception_content

Expand Down Expand Up @@ -168,7 +168,7 @@ def general_exception_handler(
traceback="".join(
traceback.TracebackException.from_exception(exc).format()
),
).dict(exclude_none=True),
).model_dump(exclude_none=True),
)


Expand Down
24 changes: 19 additions & 5 deletions cads_processing_api_service/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ def lookup_resource_by_id(
session.execute(statement).unique().scalar_one()
)
except sqlalchemy.exc.NoResultFound:
raise ogc_api_processes_fastapi.exceptions.NoSuchProcess()
raise ogc_api_processes_fastapi.exceptions.NoSuchProcess(
detail=f"dataset {resource_id} not found"
)
session.expunge(row)
return row

Expand Down Expand Up @@ -152,7 +154,9 @@ def get_resource_properties(
try:
resource_properties = tuple(session.execute(statement).one())
except sqlalchemy.exc.NoResultFound:
raise ogc_api_processes_fastapi.exceptions.NoSuchProcess()
raise ogc_api_processes_fastapi.exceptions.NoSuchProcess(
detail=f"dataset {resource_id} not found"
)
return resource_properties


Expand Down Expand Up @@ -439,9 +443,17 @@ def get_job_from_broker_db(
try:
job = cads_broker.database.get_request(request_uid=job_id, session=session)
if job.status == "dismissed":
raise ogc_api_processes_fastapi.exceptions.NoSuchJob()
raise ogc_api_processes_fastapi.exceptions.NoSuchJob(
detail=f"job {job_id} dismissed"
)
except cads_broker.database.NoResultFound:
raise ogc_api_processes_fastapi.exceptions.NoSuchJob()
raise ogc_api_processes_fastapi.exceptions.NoSuchJob(
detail=f"job {job_id} not found"
)
except cads_broker.database.InvalidRequestID:
raise ogc_api_processes_fastapi.exceptions.NoSuchJob(
detail=f"invalid job id {job_id}"
)
return job


Expand Down Expand Up @@ -472,7 +484,9 @@ def get_results_from_job(job: cads_broker.SystemRequest) -> dict[str, Any]:
asset_value = job.cache_entry.result["args"][0]
results = {"asset": {"value": asset_value}}
except Exception:
raise exceptions.JobResultsExpired()
raise exceptions.JobResultsExpired(
detail=f"results of job {job_id} expired"
)
elif job_status == "failed":
raise ogc_api_processes_fastapi.exceptions.JobResultsFailed(
status_code=fastapi.status.HTTP_400_BAD_REQUEST,
Expand Down
Loading