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

Handle missing or invalid path input for commands #318

Closed
juhoinkinen opened this issue Aug 16, 2019 · 1 comment · Fixed by #322
Closed

Handle missing or invalid path input for commands #318

juhoinkinen opened this issue Aug 16, 2019 · 1 comment · Fixed by #322
Assignees
Milestone

Comments

@juhoinkinen
Copy link
Member

juhoinkinen commented Aug 16, 2019

A full traceback is shown for trying to e.g. train on a nonexistent path:

$ annif train tfidf-fi nonexistent_path
...
  File "/home/local/jmminkin/git/Annif/annif/corpus/document.py", line 65, in documents
    with opener(self.path) as tsvfile:
FileNotFoundError: [Errno 2] No such file or directory: 'nonexistent_path'

Similarly for trying to train without a path:

$ annif train tfidf-fi
...
  File "/home/local/jmminkin/git/Annif/annif/cli.py", line 53, in open_documents
    docs = open_doc_path(paths[0])
IndexError: tuple index out of range

The first case could be resolved by adding exists=True argument to type=click.Path(). This (at least alone) does not work in the second case, for which maybe required=True could be used, but the Note on Non-Empty Variadic Arguments should be considered.

Similar tracebacks arise when using:

  • train
  • learn
  • eval
  • optimize

For some reason index behaves differently:

  • It gives proper error when not given a path:
    $ annif index tfidf-fi
    Usage: annif index [OPTIONS] PROJECT_ID DIRECTORY
    Try "annif index --help" for help.
    
    Error: Missing argument "DIRECTORY".
    
  • It does not produce any output or error with nonexistent path:
    $ annif index tfidf-fi nonexistent
    $
    
@juhoinkinen juhoinkinen changed the title Handle missing or invalid input for train command Handle missing or invalid path input for commands Aug 16, 2019
@osma
Copy link
Member

osma commented Aug 20, 2019

+1 for adding exists=True.

The note on required file arguments makes a good point.

I've sometimes (when testing VW based backends that support online learning) used a command like

annif train vw-multi /dev/null

The idea is to create an empty model which can then be trained incrementally.

I think annif train vw-multi (without a file argument) should do the same as the above, but perhaps emit an info message about creating an empty model. I'm unsure what this would do with non-VW backend though - probably there should be an error because creating an empty tfidf or fasttext model doesn't make sense.

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