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 90c14a9 commit 1b75f60
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ert/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from ert.run_models.multiple_data_assimilation import MultipleDataAssimilation
from ert.services import StorageService, WebvizErt
from ert.shared.storage.command import add_parser_options as ert_api_add_parser_options
from ert.storage import ErtStorageException
from ert.trace import trace, tracer, tracer_provider
from ert.validation import (
IntegerArgument,
Expand Down Expand Up @@ -673,7 +674,7 @@ def main() -> None:
) as context:
logger.info(f"Running ert with {args}")
args.func(args, context.plugin_manager)
except ErtCliError as err:
except (ErtCliError, ErtStorageException) as err:
span.set_status(Status(StatusCode.ERROR))
span.record_exception(err)
logger.debug(str(err))
Expand Down
20 changes: 20 additions & 0 deletions tests/ert/unit_tests/shared/test_main_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import sys
from unittest.mock import MagicMock

import filelock
import pytest

import ert
import ert.__main__ as main


Expand Down Expand Up @@ -32,3 +34,21 @@ def test_main_logging_argparse(monkeypatch, caplog):
with caplog.at_level(logging.INFO):
main.main()
assert "mode='test_run'" in caplog.text


@pytest.mark.usefixtures("copy_poly_case")
def test_storage_exception_is_not_unexpected_error(monkeypatch, caplog):
file_lock_mock = MagicMock()
caplog.set_level(logging.ERROR)

def mock_acquire(*args, **kwargs):
raise filelock.Timeout

file_lock_mock.acquire = mock_acquire
monkeypatch.setattr(ert.storage.local_storage, "FileLock", file_lock_mock)

monkeypatch.setattr(sys, "argv", ["ert", "test_run", "poly.ert"])
with pytest.raises(SystemExit) as exc_info:
main.main()
assert "ERT crashed unexpectedly" not in str(exc_info.value)
assert "Failed to open storage" in str(exc_info.value)

0 comments on commit 1b75f60

Please sign in to comment.