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 b393caf commit e078969
Show file tree
Hide file tree
Showing 2 changed files with 19 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
16 changes: 16 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 @@ -384,6 +385,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 All @@ -396,3 +410,5 @@ def test_672_missing_type(snippetcompiler):
""",
"could not find type Testt in namespace __config__"
" (reported in Implementation(test) ({dir}/main.cf:5))")


0 comments on commit e078969

Please sign in to comment.