Skip to content

Commit

Permalink
Runtsafe order bug (#1265)
Browse files Browse the repository at this point in the history
* Fix cmdr print bug on syntax err

Happens if len(line) > 60 and error was in the first 30 chars.

* Fix a storm runtsafe variable ordering bug
  • Loading branch information
jnwatson authored and vEpiphyte committed Jun 6, 2019
1 parent 40c61d7 commit b365d02
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion synapse/cmds/cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def _onErr(self, mesg):
text = text.replace('\n', ' ')
# Handle too-long text
if tlen > 60:
text = text[pos - 30:pos + 30]
text = text[max(0, pos - 30):pos + 30]
if pos < tlen - 30:
text += '...'
if pos > 30:
Expand Down
15 changes: 6 additions & 9 deletions synapse/lib/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,18 +522,15 @@ class VarEvalOper(Oper):
'''
async def run(self, runt, genr):

if self.isRuntSafe(runt):

async for item in genr:
yield item
anynodes = False
async for node, path in genr:
anynodes = True
await self.kids[0].compute(path)
yield node, path

if not anynodes and self.isRuntSafe(runt):
await self.kids[0].runtval(runt)

else:
async for node, path in genr:
await self.kids[0].compute(path)
yield node, path

class SwitchCase(Oper):

def prepare(self):
Expand Down
6 changes: 6 additions & 0 deletions synapse/tests/test_cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2768,6 +2768,12 @@ async def test_storm_ifstmt(self):
nodes = await core.nodes(q)
self.len(1, nodes)

async def test_storm_order(self):
q = '''[test:str=foo :hehe=bar] $tvar=$lib.text() $tvar.add(1) $tvar.add(:hehe) $lib.print($tvar.str()) '''
async with self.getTestCore() as core:
mesgs = await core.streamstorm(q).list()
self.stormIsInPrint('1bar', mesgs)

async def test_feed_splice(self):

iden = s_common.guid()
Expand Down

0 comments on commit b365d02

Please sign in to comment.