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

Prevent functions from throwing loop control flow exceptions; convert them into StormRuntimeError. SYN-8397 #4025

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
013bdb2
Prevent functions from throwing loop control flow exceptions; convert…
vEpiphyte Dec 5, 2024
174d26c
embed statement into the exception
vEpiphyte Dec 5, 2024
e4f4c57
Add StormLoopCtrl stop
vEpiphyte Dec 5, 2024
4cd34ae
Feedback
vEpiphyte Dec 6, 2024
1b47a1e
Merge branch 'master' into bug_func_ctrlflow_leak
vEpiphyte Dec 6, 2024
19faf66
wip
vEpiphyte Dec 6, 2024
d1a4f59
Merge branch 'master' into bug_func_ctrlflow_leak
vEpiphyte Dec 26, 2024
5e72afc
Update SynErr.errinfo manipulation to use set / update APIs.
vEpiphyte Dec 26, 2024
59bf7e3
Add code to StormCtrlFlow to make them seem close to SynErr exception…
vEpiphyte Dec 26, 2024
32a59bc
Add a FIXME / DISCUSS comment.
vEpiphyte Dec 26, 2024
2172afa
Refactor StormCtrlFlow implementation.
vEpiphyte Dec 26, 2024
335ec71
Fix up item references & Exception refs
vEpiphyte Dec 26, 2024
ad96e69
Move the Execption class into the mixin...
vEpiphyte Dec 26, 2024
a5c62da
Merge branch 'master' into bug_func_ctrlflow_leak
vEpiphyte Dec 30, 2024
b93ce40
Tidy tests for stop keyword
vEpiphyte Dec 30, 2024
6e0c1cc
Add break and continue tests
vEpiphyte Dec 30, 2024
8a893af
Merge branch 'master' into bug_func_ctrlflow_leak
vEpiphyte Dec 31, 2024
57a5d81
Chagnelog
vEpiphyte Dec 31, 2024
ab0196a
fix typo
vEpiphyte Dec 31, 2024
b4585d1
Add test for synerrmixin behavior
vEpiphyte Dec 31, 2024
1e7e5d5
Additional test coverage
vEpiphyte Dec 31, 2024
5667da7
additional exc coverage
vEpiphyte Dec 31, 2024
474a042
Add coverage for callStorm as well.
vEpiphyte Dec 31, 2024
a041e66
remove some extra calls to getLogExtra()
vEpiphyte Dec 31, 2024
fa30ce7
Apply suggestions from code review
vEpiphyte Dec 31, 2024
6f16f36
Merge branch 'bug_func_ctrlflow_leak' of github.com:vertexproject/syn…
vEpiphyte Dec 31, 2024
e993f46
updates / comments
vEpiphyte Dec 31, 2024
803ada5
Update synapse/lib/stormctrl.py
Cisphyx Jan 3, 2025
0f48d66
fix some uses of StormRuntimeError without a mesg= argument
vEpiphyte Jan 6, 2025
40a9851
Merge branch 'master' into bug_func_ctrlflow_leak
vEpiphyte Jan 6, 2025
5967611
Merge branch 'master' into bug_func_ctrlflow_leak
vEpiphyte Jan 8, 2025
1d7f6d5
Add highlight info for emit use outside of emitter functions.
vEpiphyte Jan 8, 2025
d999581
fix comment
vEpiphyte Jan 8, 2025
352f75d
Update changes/b4642a502f49353787b4f6632a6a6566.yaml
vEpiphyte Jan 8, 2025
9406e05
formatting
vEpiphyte Jan 8, 2025
993025d
remove comment
vEpiphyte Jan 8, 2025
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
10 changes: 10 additions & 0 deletions synapse/lib/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -4972,6 +4972,11 @@

except s_stormctrl.StormReturn as e:
return e.item
except s_stormctrl.StormCtrlFlow as e:
if isinstance(e, s_stormctrl.StormLoopCtrl):
mesg = f'{self.name} - Functions are not allowed to use unhandled loop control flow statements - {e._statement}'
vEpiphyte marked this conversation as resolved.
Show resolved Hide resolved
raise s_exc.StormRuntimeError(mesg=mesg) from e
vEpiphyte marked this conversation as resolved.
Show resolved Hide resolved
raise

Check warning on line 4979 in synapse/lib/ast.py

View check run for this annotation

Codecov / codecov/patch

synapse/lib/ast.py#L4976-L4979

Added lines #L4976 - L4979 were not covered by tests

async def genr():
async with runt.getSubRuntime(self.kids[2], opts=opts) as subr:
Expand All @@ -4991,5 +4996,10 @@
yield node, path
except s_stormctrl.StormStop:
return
except s_stormctrl.StormCtrlFlow as e:
if isinstance(e, s_stormctrl.StormLoopCtrl):
mesg = f'{self.name} - Functions are not allowed to use unhandled loop control flow statements - {e._statement}'
raise s_exc.StormRuntimeError(mesg=mesg) from e

Check warning on line 5002 in synapse/lib/ast.py

View check run for this annotation

Codecov / codecov/patch

synapse/lib/ast.py#L5001-L5002

Added lines #L5001 - L5002 were not covered by tests
raise

return genr()
13 changes: 10 additions & 3 deletions synapse/lib/stormctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ class StormCtrlFlow(Exception):
def __init__(self, item=None):
self.item = item

class StormLoopCtrl:
# Control flow statements for WHILE and FOR loop control and GENERATOR controls
_statement = ''

class StormExit(StormCtrlFlow): pass
class StormStop(StormCtrlFlow): pass
class StormBreak(StormCtrlFlow): pass
class StormStop(StormCtrlFlow, StormLoopCtrl):
_statement = 'stop'
class StormBreak(StormCtrlFlow, StormLoopCtrl):
_statement = 'break'
class StormReturn(StormCtrlFlow): pass
class StormContinue(StormCtrlFlow): pass
class StormContinue(StormCtrlFlow, StormLoopCtrl):
_statement = 'continue'
Loading