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

Handling errors in projects.cfg #282

Closed
juhoinkinen opened this issue Jun 12, 2019 · 2 comments · Fixed by #300
Closed

Handling errors in projects.cfg #282

juhoinkinen opened this issue Jun 12, 2019 · 2 comments · Fixed by #300
Assignees
Milestone

Comments

@juhoinkinen
Copy link
Member

Some syntax errors of projects.cfg produce a lengthy generic Python error message, see e.g. https://groups.google.com/d/msg/annif-users/kIvJPbZ-vVU/zXDYFm6PAgAJ

A more concise/specific error message would be better. Some errors are already handled, for example this exists:
"Error: Project 'maui-fi': vocab setting is missing"

@juhoinkinen
Copy link
Member Author

juhoinkinen commented Jun 12, 2019

I accidentally had placed the contents of mauiservice.ini in projects.cfg, which led to this error message:

root@lx8-9811-008:/annif_projects# annif list-projects
Project ID               Project Name                                 Language
------------------------------------------------------------------------------
kirjastonhoitaja         kirjastonhoitaja                             fi      
root@lx8-9811-008:/annif_projects# cat document.txt | annif suggest kirjastonhoitaja
Traceback (most recent call last):
  File "/usr/local/bin/annif", line 11, in <module>
    load_entry_point('annif', 'console_scripts', 'annif')()
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/flask/cli.py", line 569, in main
    return super(FlaskGroup, self).main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/flask/cli.py", line 419, in decorator
    return __ctx.invoke(f, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Annif/annif/cli.py", line 165, in run_suggest
    hits = hit_filter(project.suggest(text, backend_params))
  File "/Annif/annif/project.py", line 175, in suggest
    hits = self._suggest_with_backend(text, backend_params)
  File "/Annif/annif/project.py", line 114, in _suggest_with_backend
    beparams = backend_params.get(self.backend.backend_id, {})
  File "/Annif/annif/project.py", line 130, in backend
    backend_id = self.config['backend']
  File "/usr/local/lib/python3.6/configparser.py", line 1233, in __getitem__
    raise KeyError(key)
KeyError: 'backend'

@osma
Copy link
Member

osma commented Jun 17, 2019

Yes, this is a very good idea. Showing users a traceback is not very friendly.

This is also related to #273 which proposes that there should be default values for configuration settings. Many errors like this would be fixed by defaults, but obviously not all of them - for example a project without a backend setting cannot really work and it doesn't make sense to use a default backend in that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants