Skip to content

Commit

Permalink
Update SynErr.errinfo manipulation to use set / update APIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
vEpiphyte committed Dec 27, 2024
1 parent 5517cfb commit 8c2cd58
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
7 changes: 6 additions & 1 deletion synapse/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ def setdefault(self, name, valu):
self.errinfo[name] = valu
self._setExcMesg()

def update(self, items: dict):
'''Update multiple items in the errinfo dict at once.'''
self.errinfo.update(**items)
self._setExcMesg()

class StormRaise(SynErr):
'''
This represents a user provided exception inside of a Storm runtime. It requires a errname key.
This represents a user provided exception raised in the Storm runtime. It requires a errname key.
'''
def __init__(self, *args, **info):
SynErr.__init__(self, *args, **info)
Expand Down
2 changes: 1 addition & 1 deletion synapse/lib/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def getPosInfo(self):

def addExcInfo(self, exc):
if 'highlight' not in exc.errinfo:
exc.errinfo['highlight'] = self.getPosInfo()
exc.set('highlight', self.getPosInfo())
return exc

def repr(self):
Expand Down
2 changes: 1 addition & 1 deletion synapse/lib/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def _larkToSynExc(self, e):
origexc = e.orig_exc
if not isinstance(origexc, s_exc.SynErr):
raise e.orig_exc # pragma: no cover
origexc.errinfo['text'] = self.text
origexc.set('text', self.text)
return s_exc.BadSyntax(**origexc.errinfo)

elif isinstance(e, lark.exceptions.UnexpectedCharacters): # pragma: no cover
Expand Down
8 changes: 4 additions & 4 deletions synapse/lib/snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ async def _set(self, prop, valu, norminfo=None, ignore_ro=False):
valu, norminfo = prop.type.norm(valu)
except s_exc.BadTypeValu as e:
oldm = e.errinfo.get('mesg')
e.errinfo['prop'] = prop.name
e.errinfo['form'] = prop.form.name
e.errinfo['mesg'] = f'Bad prop value {prop.full}={valu!r} : {oldm}'
e.update({'prop': prop.name,
'form': prop.form.name,
'mesg': f'Bad prop value {prop.full}={valu!r} : {oldm}'})
if self.ctx.snap.strict:
raise e
await self.ctx.snap.warn(e)
Expand Down Expand Up @@ -493,7 +493,7 @@ async def _addNode(self, form, valu, props=None, norminfo=None):
try:
valu, norminfo = form.type.norm(valu)
except s_exc.BadTypeValu as e:
e.errinfo['form'] = form.name
e.set('form', form.name)
if self.snap.strict: raise e
await self.snap.warn(f'addNode() BadTypeValu {form.name}={valu} {e}')
return None
Expand Down

0 comments on commit 8c2cd58

Please sign in to comment.