Repository: conan-io/conan

Issue:
Return errorcode 6 when settings are constrained to not support the current environment
There are two approaches to restrict the environment a recipe is working for: [Constrain Settings and Options](https://docs.conan.io/en/latest/mastering/conditional.html?highlight=conaninvalidconfiguration#constrain-settings-and-options)

When using the first approach and raising a `ConanInvalidConfiguration` Conan returns with errorcode 6. This could be further processed by scripts/CI perfectly. However the second approach with constraining the settings does not return with errorcode 6, but results in an [error](http://docs.conan.io/en/latest/faq/troubleshooting.html#error-invalid-setting) and errorcode 1 instead.

Is there a reason why both return with different behaviour? It would be perfect if both would return with errorcode 6, so developers could use both methods and scripts/CI can react on that in the same way.


Discussion:

Resolving patch:
diff --git a/conans/client/loader.py b/conans/client/loader.py
--- a/conans/client/loader.py
+++ b/conans/client/loader.py
@@ -139,6 +139,8 @@ def load_consumer(self, conanfile_path, processed_profile, name=None, version=No
             processed_profile._user_options.clear_unscoped_options()
 
             return conanfile
+        except ConanInvalidConfiguration:
+            raise
         except Exception as e:  # re-raise with file name
             raise ConanException("%s: %s" % (conanfile_path, str(e)))
 


Test patch:
diff --git a/conans/test/functional/command/invalid_configuration_test.py b/conans/test/functional/command/invalid_configuration_test.py
--- a/conans/test/functional/command/invalid_configuration_test.py
+++ b/conans/test/functional/command/invalid_configuration_test.py
@@ -33,6 +33,14 @@ def test_install_method(self):
         self.assertIn("Invalid configuration: user says that compiler.version=12 is invalid",
                       self.client.out)
 
+    def test_info_method(self):
+        self.client.run("info . %s" % self.settings_msvc15)
+
+        error = self.client.run("info . %s" % self.settings_msvc12,
+                                assert_error=True)
+        self.assertEqual(error, ERROR_INVALID_CONFIGURATION)
+        self.assertIn("ERROR: conanfile.py: Invalid configuration: user says that compiler.version=12 is invalid", self.client.out)
+
     def test_create_method(self):
         self.client.run("create . name/ver@jgsogo/test %s" % self.settings_msvc15)
 
@@ -60,7 +68,22 @@ class MyPkg(ConanFile):
         self.assertIn("name/ver@jgsogo/test: Invalid configuration: user says that "
                       "compiler.version=12 is invalid", self.client.out)
 
-    def restricted_settings_raise_invalid_code_too_test(self):
+    def test_restricted_settings_raise_invalid_code_too_test_info(self):
+        self.client.save({"conanfile.py": """
+from conans import ConanFile
+from conans.errors import ConanInvalidConfiguration
+
+class MyPkg(ConanFile):
+    requires = "name/ver@jgsogo/test"
+    settings = {"arch": ["x86_64"]}
+"""})
+
+        error = self.client.run("info . -s arch=x86", assert_error=True)
+        self.assertEqual(error, ERROR_INVALID_CONFIGURATION)
+
+
+
+    def test_restricted_settings_raise_invalid_code_too_test_create(self):
         self.client.save({"conanfile.py": """
 from conans import ConanFile
 from conans.errors import ConanInvalidConfiguration