diff --git a/synapse/exc.py b/synapse/exc.py index fe115b6305..8c5b2ef752 100644 --- a/synapse/exc.py +++ b/synapse/exc.py @@ -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) diff --git a/synapse/lib/ast.py b/synapse/lib/ast.py index a934853308..dce4d2eed9 100644 --- a/synapse/lib/ast.py +++ b/synapse/lib/ast.py @@ -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): diff --git a/synapse/lib/parser.py b/synapse/lib/parser.py index 798058c66b..614f0ab7c3 100644 --- a/synapse/lib/parser.py +++ b/synapse/lib/parser.py @@ -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 diff --git a/synapse/lib/snap.py b/synapse/lib/snap.py index 511b3665b2..656f44a252 100644 --- a/synapse/lib/snap.py +++ b/synapse/lib/snap.py @@ -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) @@ -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