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

improved error reporting on bad assignment #680

Merged
merged 3 commits into from
Jun 29, 2018
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
3 changes: 3 additions & 0 deletions src/inmanta/ast/statements/assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ def resume(self,
queue: QueueScheduler,
target: ResultVariable) -> None:
instance = self.instance.execute(requires, resolver, queue)
if not isinstance(instance, Instance):
raise TypingException(self, "The object at %s is not an Entity but a %s with value %s" %
(self.instance, type(instance), instance))
var = instance.get_attribute(self.attribute_name)
if self.list_only and not var.is_multi():
raise TypingException(self, "Can not use += on relations with multiplicity 1")
Expand Down
13 changes: 13 additions & 0 deletions tests/test_compiler_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,19 @@ def test_610_multi_add(snippetcompiler):
" attribute b ({dir}/main.cf:11:11) requires 2 values but only 1 are set")


def test_670_assign_on_relation(snippetcompiler):
snippetcompiler.setup_for_error_re(
"""
h = std::Host(name="test", os=std::linux)
f = std::ConfigFile(host=h, path="a", content="")

h.files.path = "1"

""",
"The object at h.files is not an Entity but a <class 'list'> with value \[std::ConfigFile [0-9a-fA-F]+\]"
" \(reported in h.files.path = '1' \({dir}/main.cf:5\)\)")


def test_672_missing_type(snippetcompiler):
snippetcompiler.setup_for_error(
"""
Expand Down