# HG changeset patch
# User Georges Racinet <georges.racinet@octobus.net>
# Date 1699637411 -3600
#      Fri Nov 10 18:30:11 2023 +0100
# Node ID aa9616db6ffb0f092bfed466cc20a64fb4443640
# Parent  0625250d68c258a8df3c735e9dc46b95c3de93dc
GitLab 16.2: matching error details for missing repo and unknown storage

In the case of unknown storage, we find it useful to repeat the requested
name, hence we simply stop comparing exactly the details.

In the case of the missing repository field, the new upstream message
is clearly better, so we adopt it.

diff --git a/hgitaly/service/repository.py b/hgitaly/service/repository.py
--- a/hgitaly/service/repository.py
+++ b/hgitaly/service/repository.py
@@ -179,7 +179,7 @@
             if exc.args[0] == 'storage':
                 context.abort(
                     StatusCode.INVALID_ARGUMENT,
-                    f'GetStorageByName: no such storage: "{exc.args[1]}"'
+                    f'storage not found: "{exc.args[1]}"'
                 )
             exists = False
         except ValueError as exc:
@@ -595,7 +595,7 @@
         first_req = next(request)
         repo_msg = first_req.repository
         if not (repo_msg.storage_name or repo_msg.relative_path):
-            context.abort(StatusCode.INVALID_ARGUMENT, 'empty Repository')
+            context.abort(StatusCode.INVALID_ARGUMENT, 'repository not set')
 
         repo = self.load_repo(first_req.repository, context)
         patterns = itertools.chain(
@@ -689,8 +689,7 @@
         if root_dir is None:
             context.abort(
                 StatusCode.INVALID_ARGUMENT,
-                'remove all: GetStorageByName: '
-                'no such storage: "%s"' % storage
+                'remove all: storage not found: "%s"' % storage
             )
 
         root_dir = Path(os.fsdecode(root_dir)).resolve()
diff --git a/hgitaly/service/tests/test_repository_service.py b/hgitaly/service/tests/test_repository_service.py
--- a/hgitaly/service/tests/test_repository_service.py
+++ b/hgitaly/service/tests/test_repository_service.py
@@ -1116,7 +1116,7 @@
             tmpdir / 'temp_bname', [b'refs/heads/branch/default'],
             without_repository=True)
     assert exc_info_hg.value.code() == grpc.StatusCode.INVALID_ARGUMENT
-    assert exc_info_hg.value.details() == 'empty Repository'
+    assert exc_info_hg.value.details() == 'repository not set'
 
     # test incrementality with negative revspecs
 
diff --git a/hgitaly/servicer.py b/hgitaly/servicer.py
--- a/hgitaly/servicer.py
+++ b/hgitaly/servicer.py
@@ -215,7 +215,7 @@
         if not storage_name:
             # this is the best detection of a missing `repository` field
             # in request, without having the request object itself
-            raise ValueError('empty repository')
+            raise ValueError('repository not set')
 
         root_dir = self.storages.get(storage_name)
         if root_dir is None:
diff --git a/rust/rhgitaly/src/repository.rs b/rust/rhgitaly/src/repository.rs
--- a/rust/rhgitaly/src/repository.rs
+++ b/rust/rhgitaly/src/repository.rs
@@ -57,9 +57,7 @@
 /// and more like this with time (e.g., as internal Git error get catched and handled).
 pub fn default_repo_spec_error_status(err: RepoSpecError) -> Status {
     match err {
-        RepoSpecError::MissingSpecification => {
-            Status::invalid_argument("missing repository specification")
-        }
+        RepoSpecError::MissingSpecification => Status::invalid_argument("repository not set"),
         RepoSpecError::UnknownStorage(storage) => Status::invalid_argument(format!(
             "GetStorageByName: no such storage: \"{}\"",
             storage
diff --git a/tests_with_gitaly/test_repository_service.py b/tests_with_gitaly/test_repository_service.py
--- a/tests_with_gitaly/test_repository_service.py
+++ b/tests_with_gitaly/test_repository_service.py
@@ -152,8 +152,6 @@
     with pytest.raises(grpc.RpcError) as exc_info_git:
         do_rpc('git', rel_path, storage='cargoship')
     assert exc_info_hg.value.code() == exc_info_git.value.code()
-    assert 'no such storage' in exc_info_hg.value.details()
-    assert 'no such storage' in exc_info_git.value.details()
 
     # test with a broken symlink (which points to itself)
     # it used to be an error for both, with Gitaly complaining
@@ -702,4 +700,4 @@
     assert_compare_errors = rpc_helper.assert_compare_errors
 
     # unknown storage
-    assert_compare_errors(storage_name='unknown')
+    assert_compare_errors(storage_name='unknown', same_details=False)