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

Fail gracefully if no output file option is given to neurom check #991

Closed
sanjayankur31 opened this issue Mar 3, 2022 · 2 comments · Fixed by #992
Closed

Fail gracefully if no output file option is given to neurom check #991

sanjayankur31 opened this issue Mar 3, 2022 · 2 comments · Fixed by #992

Comments

@sanjayankur31
Copy link

Currently if one forgets to give the -o flag to neurom check, it results in a crash which does not really tell the user what they've done wrong:

$ neurom check A1-May29-IR2-3-G.ASC
ERROR:neurom.check.runner:                           Has axon FAIL
ERROR:neurom.check.runner:            Has nonzero soma radius FAIL
ERROR:neurom.check.runner:                                ALL FAIL
Traceback (most recent call last):
  File "/usr/bin/neurom", line 8, in <module>
    sys.exit(cli())
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1062, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1668, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3.10/site-packages/click/core.py", line 763, in invoke
    return __callback(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/neurom/apps/cli.py", line 113, in check
    morph_check.main(datapath, config, output)
  File "/usr/lib/python3.10/site-packages/neurom/apps/morph_check.py", line 51, in main
    with open(output, 'w') as json_output:
TypeError: expected str, bytes or os.PathLike object, not NoneType

However, looking at the --help text, it isnt' clear that the -o flag is necessary:

$ neurom check --help
Usage: neurom check [OPTIONS] DATAPATH

  Cli for apps/morph_check.

Options:
  -C, --config FILE  Configuration File  [default: /usr/lib/python3.10/site-
                     packages/neurom/apps/config/morph_check.yaml]
  -o, --output FILE  Path to output json summary file
  --help             Show this message and exit.

because the -C flag isn't necessary---it falls back to the default config file.

So, if the the -o flag is necessary, the command should not run at all if it isn't set. Another option is to just print the output to stdout if the flag is not set, but then that means that the flag is not necessary.

@eleftherioszisis
Copy link
Contributor

Thank you @sanjayankur31 for reporting this issue.

I have submitted a PR in which I enabled the required argument in the cli option so that it is caught early.

The following output will be produced when the output path is omitted:

Usage: neurom check [OPTIONS] DATAPATH
Try 'neurom check --help' for help.

Error: Missing option '-o' / '--output'.

@sanjayankur31
Copy link
Author

Thanks very much @eleftherioszisis

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

Successfully merging a pull request may close this issue.

2 participants