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

Feature StormVarListError messages #2013

Merged
merged 3 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 8 additions & 4 deletions synapse/lib/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,8 @@ async def run(self, runt, genr):
if isinstance(name, (list, tuple)):

if len(name) != len(item):
raise s_exc.StormVarListError(names=name, vals=item)
mesg = 'Number of items to unpack does not match the number of variables.'
raise s_exc.StormVarListError(mesg=mesg, names=name, vals=item)

for x, y in itertools.zip_longest(name, item):
path.setVar(x, y)
Expand Down Expand Up @@ -606,7 +607,8 @@ async def run(self, runt, genr):
if isinstance(name, (list, tuple)):

if len(name) != len(item):
raise s_exc.StormVarListError(names=name, vals=item)
mesg = 'Number of items to unpack does not match the number of variables.'
raise s_exc.StormVarListError(mesg=mesg, names=name, vals=item)

for x, y in itertools.zip_longest(name, item):
runt.setVar(x, y)
Expand Down Expand Up @@ -831,7 +833,8 @@ async def run(self, runt, genr):

item = await vkid.compute(runt, path)
if len(item) < len(names):
raise s_exc.StormVarListError(names=names, vals=item)
mesg = 'Attempting to assign more items then we have variable to assign too.'
raise s_exc.StormVarListError(mesg=mesg, names=names, vals=item)

for name, valu in zip(names, item):
runt.setVar(name, valu)
Expand All @@ -843,7 +846,8 @@ async def run(self, runt, genr):

item = await vkid.compute(runt, None)
if len(item) < len(names):
raise s_exc.StormVarListError(names=names, vals=item)
mesg = 'Attempting to assign more items then we have variable to assign too.'
vEpiphyte marked this conversation as resolved.
Show resolved Hide resolved
raise s_exc.StormVarListError(mesg=mesg, names=names, vals=item)

for name, valu in zip(names, item):
runt.setVar(name, valu)
Expand Down
8 changes: 8 additions & 0 deletions synapse/tests/test_cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,14 @@ async def test_storm_varlistset(self):
for node in nodes:
self.eq(node.ndef, ('inet:fqdn', 'vertex.link'))

text = '.created ($foo, $bar, $baz) = $blob'
with self.raises(s_exc.StormVarListError):
await core.nodes(text, opts)

text = '($foo, $bar, $baz) = $blob'
with self.raises(s_exc.StormVarListError):
await core.nodes(text, opts)

async def test_storm_contbreak(self):

async with self.getTestCore() as core:
Expand Down