Closed arrrobase closed 4 years ago
Basically fine. Though the language is funny. Shouldn't the log report "Error" rather than "skipping"?
Also typically we've been using code like
raise ValueError("keyword not found")
I'll amend the commit to fix the log message.
My understanding was that a simple raise
will raise the actual error that occurred in the try
block, whereas a new raise KeyError('message')
will generate a new error that gets added to the exception chain. If the error context is complicated enough the new error can make it hard to see what's happening.
https://docs.python.org/3/reference/simple_stmts.html#raise https://docs.python.org/3/tutorial/errors.html#raising-exceptions
I can replace it with raise ValueError("keyword not found")
if that's preferable.
Added custom error KeywordMissingError
. Raised if keyword is not in registry. The stack trace now looks like this for the modelname fakehead.ozgf.fs100.ch18-ld-sev_dlog-wc.18x3.g-fir.3x15-lvl.1-dexp.1_init-basic
:
[nems.xform_helper INFO] Initializing modelspec(s) for recording/model None/fakehead.ozgf.fs100.ch18-ld-sev_dlog-wc.18x3.g-fir.3x15-lvl.1-dexp.1_init-basic...
Traceback (most recent call last):
File "/home/tomlinsa/anaconda3/envs/nems/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3326, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-4d4fc6e72af3>", line 1, in <module>
runfile('/home/tomlinsa/.PyCharmCE2019.3/config/scratches/scratch.py', wdir='/home/tomlinsa/.PyCharmCE2019.3/config/scratches')
File "/snap/pycharm-community/169/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "/snap/pycharm-community/169/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/tomlinsa/.PyCharmCE2019.3/config/scratches/scratch.py", line 7, in <module>
xfspec, ctx = fit_model_xform(cellid, batch, modelname, save_file=False, saveInDB=False)
File "/home/tomlinsa/code/NEMS/nems/xform_helper.py", line 178, in fit_model_xform
autoPlot=autoPlot)
File "/home/tomlinsa/code/NEMS/nems/xform_helper.py", line 97, in generate_xforms_spec
xfspec.extend(_parse_kw_string(load_keywords, xforms_lib))
File "/home/tomlinsa/code/NEMS/nems/xform_helper.py", line 279, in _parse_kw_string
xfspec.extend(registry[kw])
File "/home/tomlinsa/code/NEMS/nems/registry.py", line 69, in __getitem__
kw = self.lookup(kw_string)
File "/home/tomlinsa/code/NEMS/nems/registry.py", line 98, in lookup
raise KeywordMissingError(kw_head)
nems.registry.KeywordMissingError: "fakehead" could not be found in the keyword registry.
Solves #161