Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve settings.yml error messages #13748

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions conans/client/cache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,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