Skip to content

Commit

Permalink
Improve exception quality
Browse files Browse the repository at this point in the history
Avoid confusing "During handling of the above exception, another
exception occurred"
  • Loading branch information
soxofaan committed Oct 30, 2024
1 parent 0376cf3 commit d74fe5e
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/openeo_aggregator/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,12 +636,12 @@ def evaluate(self, process_graph: dict, env: EvalEnv = None):
)
except openeo.rest.OpenEoApiError as e:
_log.error(f"Sync processing on {con.id!r} failed with API error {e!r}", exc_info=True)
raise pass_through_api_error(e)
raise pass_through_api_error(e) from None
except Exception as e:
_log.error(f"Sync processing on {con.id!r} failed with unexpected error {e=}", exc_info=True)
raise openeo_driver.errors.OpenEOApiException(
code="Internal", message=f"Synchronous processing failed on {con.id!r} with {e!r}"
)
) from e

return streaming_flask_response(backend_response, chunk_size=get_backend_config().streaming_chunk_size)

Expand Down Expand Up @@ -1027,9 +1027,9 @@ def _translate_job_errors(self, job_id):
yield
except openeo.rest.OpenEoApiError as e:
if e.code == JobNotFoundException.code:
raise JobNotFoundException(job_id=job_id)
raise JobNotFoundException(job_id=job_id) from None
# By default, pass through API errors.
raise pass_through_api_error(e)
raise pass_through_api_error(e) from None

def get_job_info(self, job_id: str, user_id: str) -> BatchJobMetadata:
con, backend_job_id = self._get_connection_and_backend_job_id(aggregator_job_id=job_id)
Expand Down Expand Up @@ -1338,10 +1338,12 @@ def _create_service(
except OpenEoApiError as e:
for exc_class in [ProcessGraphMissingException, ProcessGraphInvalidException]:
if e.code == exc_class.code:
raise exc_class
raise OpenEOApiException(f"Failed to create secondary service on backend {backend_id!r}: {e!r}")
raise exc_class from None
raise OpenEOApiException(
f"Failed to create secondary service on backend {backend_id!r}: {e!r}"
) from None
except (OpenEoRestError, OpenEoClientException) as e:
raise OpenEOApiException(f"Failed to create secondary service on backend {backend_id!r}: {e!r}")
raise OpenEOApiException(f"Failed to create secondary service on backend {backend_id!r}: {e!r}") from e

return ServiceIdMapping.get_aggregator_service_id(service.service_id, backend_id)

Expand Down Expand Up @@ -1406,7 +1408,7 @@ def _get_connection(self, process_graph_id: Optional[str] = None) -> Iterator[op
yield con
except OpenEoApiError as e:
if e.code == ProcessGraphNotFoundException.code:
raise ProcessGraphNotFoundException(process_graph_id=process_graph_id)
raise ProcessGraphNotFoundException(process_graph_id=process_graph_id) from None
raise

def get(self, user_id: str, process_id: str) -> Union[UserDefinedProcessMetadata, None]:
Expand Down Expand Up @@ -1538,7 +1540,7 @@ def user_access_validation(self, user: User, request: flask.Request) -> User:
"userinfo keys": (user.info.keys(), user.info.get("oidc_userinfo", {}).keys()),
},
)
raise PermissionsInsufficientException(enrollment_error_user_message)
raise PermissionsInsufficientException(enrollment_error_user_message) from e

roles = openeo_aggregator.egi.OPENEO_PLATFORM_USER_ROLES.extract_roles(eduperson_entitlements)
if roles:
Expand Down

0 comments on commit d74fe5e

Please sign in to comment.