Skip to content

Commit

Permalink
improve settings.yml error messages (#13748)
Browse files Browse the repository at this point in the history
Changelog: Feature: Improve settings.yml error messages
Docs: Omit

Close #13738
  • Loading branch information
AbrilRBS authored Apr 21, 2023
2 parents 944fdfc + a554aea commit 2812d53
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 1 addition & 4 deletions conans/client/cache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,7 @@ def appending_recursive_dict_update(d, u):

appending_recursive_dict_update(settings, settings_user)

try:
return Settings(settings)
except AttributeError as e:
raise ConanException("Invalid settings.yml format: {}".format(e))
return Settings(settings)

def initialize_settings(self):
# TODO: This is called by ConfigAPI.init(), maybe move everything there?
Expand Down
3 changes: 3 additions & 0 deletions conans/model/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ def __init__(self, definition=None, name="settings", parent_value="settings"):
if parent_value is None and definition:
raise ConanException("settings.yml: null setting can't have subsettings")
definition = definition or {}
if not isinstance(definition, dict):
val = "" if parent_value == "settings" else f"={parent_value}"
raise ConanException(f"Invalid settings.yml format: '{name}{val}' is not a dictionary")
self._name = name # settings, settings.compiler
self._parent_value = parent_value # gcc, x86
self._data = {k: SettingsItem(v, "%s.%s" % (name, k))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
class TestSettingsLoad:
def test_invalid_settings(self):
client = TestClient()
client.save({os.path.join(client.cache_folder, 'settings.yml'): """your buggy file""",
client.save({os.path.join(client.cache_folder, 'settings.yml'): "your buggy file",
"conanfile.txt": ""})
client.run("install .", assert_error=True)
assert "ERROR: Invalid settings.yml format" in client.out
assert "ERROR: Invalid settings.yml format: 'settings' is not a dictionary" in client.out
client.save({os.path.join(client.cache_folder, 'settings.yml'): "os:\n Windows: [1, ]",
"conanfile.txt": ""})
client.run("install .", assert_error=True)
assert "ERROR: Invalid settings.yml format: 'settings.os=Windows' is not a dictionary" \
in client.out

def test_invalid_yaml(self):
client = TestClient()
Expand Down

0 comments on commit 2812d53

Please sign in to comment.