Skip to content

Commit

Permalink
Add highlight info for emit use outside of emitter functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
vEpiphyte committed Jan 8, 2025
1 parent 5967611 commit 1d7f6d5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 8 additions & 2 deletions synapse/lib/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -4830,12 +4830,18 @@ async def run(self, runt, genr):
count = 0
async for node, path in genr:
count += 1
await runt.emit(await self.kids[0].compute(runt, path))
try:
await runt.emit(await self.kids[0].compute(runt, path))
except s_exc.StormRuntimeError as e:
raise self.addExcInfo(e)
yield node, path

# no items in pipeline and runtsafe. execute once.
if count == 0 and self.isRuntSafe(runt):
await runt.emit(await self.kids[0].compute(runt, None))
try:
await runt.emit(await self.kids[0].compute(runt, None))
except s_exc.StormRuntimeError as e:
raise self.addExcInfo(e)

class Stop(Oper):

Expand Down
11 changes: 9 additions & 2 deletions synapse/tests/test_lib_storm.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,16 @@ async def test_lib_storm_emit(self):
prnt = [m[1]['mesg'] for m in msgs if m[0] == 'print']
self.eq(prnt, ['inner 0', 'outer 0'])

await self.asyncraises(s_exc.StormRuntimeError, core.nodes('emit foo'))
# Emit outside an emitter function raises a runtime error with posinfo
with self.raises(s_exc.StormRuntimeError) as cm:
await core.nodes('emit foo')
self.nn(cm.exception.get('highlight'))

with self.raises(s_exc.StormRuntimeError) as cm:
await core.nodes('[test:str=emit] emit foo')
self.nn(cm.exception.get('highlight'))

# stop cannot cross function boundaries
# stop cannot cross function boundaries
q = '''
function inner(v) {
if ( $v = 2 ) {
Expand Down

0 comments on commit 1d7f6d5

Please sign in to comment.