Repository: conan-io/conan
Pull request: Raise if using 'conan search ... --revisions' with the feature disabled
Changelog: omit
Docs: omit

closes #4576 

@REVISIONS: 1


Problem statement:
[revisions] Error on search recipe revisions in remote
When revisions are NOT enabled in the Conan Client and a remote search or recipe revisions is done, Conan errors with:

```
$ conan search wiringpi/2.46@conan/stable --revisions -r conan-virtual
ERROR: The remote doesn't support revisions. [Remote: conan-virtual]
```
H
owever, the remote DOES support revisions and the fault is in the client not having them activated and thus not being able to talk via V2 with the remote.

There should be raise early in the code saying that revisions are not enabled, then, if the user enables revisions and finally the remote DOES NOT support revisions, the message ``ERROR: The remote doesn't support revisions. [Remote: conan-virtual]`` would be valid

----------------------------------------

There could be also the option of disabling the ``--revisions`` flag even for local search when revisions are not enabled

Hints from issue discussion:

Commit message: raise if using --revisions in search command with the feature disabled

Patch to review:
diff --git a/conans/client/command.py b/conans/client/command.py
index 7cd41e5c406..68a57f696a9 100644
--- a/conans/client/command.py
+++ b/conans/client/command.py
@@ -1017,8 +1017,15 @@ def search(self, *args):
         parser.add_argument("-rev", "--revisions", default=False, action='store_true',
                             help='Get a list of revisions for a reference or a '
                                  'package reference.')
+
         args = parser.parse_args(*args)
 
+        if args.revisions and not self._cache.config.revisions_enabled:
+            raise ConanException("This client doesn't support revisions. Enable this feature setting"
+                                 " to 'True' the environment variable 'CONAN_REVISIONS_ENABLED'"
+                                 " or the config value 'general.revisions_enabled' in your"
+                                 " conan.conf file")
+
         if args.table and args.json:
             raise ConanException("'--table' argument cannot be used together with '--json'")
 
diff --git a/conans/test/functional/command/search_test.py b/conans/test/functional/command/search_test.py
index ab4de8dc421..4f0175dd4d9 100644
--- a/conans/test/functional/command/search_test.py
+++ b/conans/test/functional/command/search_test.py
@@ -1359,6 +1359,12 @@ def test_invalid_references_test(self):
                    assert_error=True)
         self.assertIn("Cannot list the revisions of a specific package revision", client.out)
 
+    def test_exception_client_without_revs(self):
+        client = TestClient()
+        client.run("search whatever --revisions", assert_error=True)
+        self.assertIn("ERROR: This client doesn't support revisions", client.out)
+
+
 class SearchRemoteAllTestCase(unittest.TestCase):
     def setUp(self):
         """ Create a remote called 'all' with some recipe in it """


Code review comments:
diff_hunk: @@ -1017,8 +1017,15 @@ def search(self, *args):
         parser.add_argument("-rev", "--revisions", default=False, action='store_true',
                             help='Get a list of revisions for a reference or a '
                                  'package reference.')
+
         args = parser.parse_args(*args)
 
+        if args.revisions and not self._cache.config.revisions_enabled:
+            raise ConanException("This client doesn't support revisions. Enable this feature setting"
path: conans/client/command.py
text: @user1:
The client supports revisions, but they are not activated. I would change the message to: 
```
The client doesn't have the revisions feature enabled. Enable this feature ...
```
I also prefer the value to `1` instead of `True`

@user1:
I think this PR could also contain the fix for https://github.com/conan-io/conan/issues/4607
The message probably should be shared. Could make sense to create an exception `RevisionsDisabledException` and catch the error printing the message?

@author:
I'm not sure if the custom exception would work out of the box, it will inherit from `ConanException`, and in #4607 it will be raised from the `RestApiClient::_get_api` function, I think there is a high chance for that exception to be captured before reaching the `conan_api` world.

So, although it is a good idea (👍 ), I will eventually add it in the other issue