Skip to content

Commit

Permalink
Improve UX for permission errors in storage
Browse files Browse the repository at this point in the history
This commit:
* Improves the error message displayed when the dark storage server does not have access to the storage path.
* Makes the dark storage server return a response with status code 401 - unauthorized when the `get_ensemble_record` endpoint fails due to `PermissionError`.
* Makes the failed message in `LegacyEnsemble._evaluate_inner` omit stacktrace when it failed due to PermissionError, making it shorter and more consise.
  • Loading branch information
jonathan-eq committed Dec 6, 2024
1 parent 726a273 commit 90c14a9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/ert/dark_storage/endpoints/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ async def get_record_observations(
"text/csv": {},
"application/x-parquet": {},
}
}
},
status.HTTP_401_UNAUTHORIZED: {
"content": {
"application/json": {"example": {"error": "Unauthorized access"}}
},
},
},
)
async def get_ensemble_record(
Expand All @@ -77,7 +82,10 @@ async def get_ensemble_record(
accept: Annotated[Union[str, None], Header()] = None,
) -> Any:
name = unquote(name)
dataframe = data_for_key(storage.get_ensemble(ensemble_id), name)
try:
dataframe = data_for_key(storage.get_ensemble(ensemble_id), name)
except PermissionError as e:
raise HTTPException(status_code=401, detail=str(e)) from e
media_type = accept if accept is not None else "text/csv"
if media_type == "application/x-parquet":
dataframe.columns = [str(s) for s in dataframe.columns]
Expand Down
5 changes: 4 additions & 1 deletion src/ert/ensemble_evaluator/_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,10 @@ async def _evaluate_inner( # pylint: disable=too-many-branches

self._scheduler.add_dispatch_information_to_jobs_file()
result = await self._scheduler.execute(min_required_realizations)

except PermissionError as error:
logger.exception((f"Unexpected exception in ensemble: \n {error!s}"))
await event_unary_send(event_creator(Id.ENSEMBLE_FAILED))
return
except Exception as exc:
logger.exception(
(
Expand Down
2 changes: 2 additions & 0 deletions src/ert/gui/tools/plot/plot_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def get_all_ensembles(self) -> List[EnsembleObject]:

@staticmethod
def _check_response(response: httpx._models.Response) -> None:
if response.status_code == httpx.codes.UNAUTHORIZED:
raise httpx.RequestError(message=f"{response.text}")
if response.status_code != httpx.codes.OK:
raise httpx.RequestError(
f" Please report this error and try restarting the application."
Expand Down
2 changes: 1 addition & 1 deletion src/ert/gui/tools/plot/plottery/plots/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def plotHistogram(
if use_log_scale:
axes[ensemble.name].set_xscale("log")

if not data[ensemble.name].empty:
if ensemble.name in data and not data[ensemble.name].empty:
if categorical:
config.addLegendItem(
ensemble.name,
Expand Down

0 comments on commit 90c14a9

Please sign in to comment.