Skip to content

Commit

Permalink
improved error reporting on bad assignment
Browse files Browse the repository at this point in the history
fixes #670
  • Loading branch information
wouterdb authored and bartv committed Jun 29, 2018
1 parent d01ec45 commit 6daac9e
Show file tree
Hide file tree
Showing 2 changed files with 17 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
14 changes: 14 additions & 0 deletions tests/test_compiler_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Contact: code@inmanta.com
"""
from conftest import snippetcompiler


def test_plugin_excn(snippetcompiler):
Expand Down Expand Up @@ -382,3 +383,16 @@ def test_610_multi_add(snippetcompiler):
""",
"The object __config__::A (instantiated at {dir}/main.cf:13) is not complete:"
" 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\)\)")

0 comments on commit 6daac9e

Please sign in to comment.