Skip to content

Commit

Permalink
improved error reporting on bad assignment (#680)
Browse files Browse the repository at this point in the history
* improved error reporting on bad assignment

fixes #670
  • Loading branch information
wouterdb authored and bartv committed Jun 29, 2018
1 parent fbfabae commit 9ad5644
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
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

0 comments on commit 9ad5644

Please sign in to comment.