Skip to content

Commit

Permalink
Raise invalid configuration when restricted (#5178)
Browse files Browse the repository at this point in the history
  • Loading branch information
lasote authored and memsharded committed May 23, 2019
1 parent a64c3f4 commit bda97a2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion conans/client/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from conans.client.generators import registered_generators
from conans.client.loader_txt import ConanFileTextLoader
from conans.client.tools.files import chdir
from conans.errors import ConanException, NotFoundException
from conans.errors import ConanException, NotFoundException, ConanInvalidConfiguration
from conans.model.conan_file import ConanFile
from conans.model.conan_generator import Generator
from conans.model.options import OptionsValues
Expand Down Expand Up @@ -136,6 +136,8 @@ def load_conanfile(self, conanfile_path, processed_profile, ref):
try:
self._initialize_conanfile(conanfile, processed_profile)
return conanfile
except ConanInvalidConfiguration:
raise
except Exception as e: # re-raise with file name
raise ConanException("%s: %s" % (conanfile_path, str(e)))

Expand Down
4 changes: 2 additions & 2 deletions conans/model/conan_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from conans.client.output import Color, ScopedOutput
from conans.client.tools.env import environment_append, no_op, pythonpath
from conans.client.tools.oss import OSInfo
from conans.errors import ConanException
from conans.errors import ConanException, ConanInvalidConfiguration
from conans.model.build_info import DepsCppInfo
from conans.model.env_info import DepsEnvInfo
from conans.model.options import Options, OptionsValues, PackageOptions
Expand Down Expand Up @@ -59,7 +59,7 @@ def create_settings(conanfile, settings):
settings.constraint(current)
return settings
except Exception as e:
raise ConanException("Error while initializing settings. %s" % str(e))
raise ConanInvalidConfiguration("Error while initializing settings. %s" % str(e))


@contextmanager
Expand Down
13 changes: 13 additions & 0 deletions conans/test/functional/command/invalid_configuration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,16 @@ class MyPkg(ConanFile):
self.assertEqual(error, ERROR_INVALID_CONFIGURATION)
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):
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("create . lib/1.0@user/channel -s arch=x86", assert_error=True)
self.assertEqual(error, ERROR_INVALID_CONFIGURATION)

0 comments on commit bda97a2

Please sign in to comment.