NDAR / nda-tools

Python package for interacting with NDA web services. Used to validate, submit, and download data to and from NDA.
MIT License
47 stars 22 forks source link

Unclear Error when non-existent package requested #60

Closed pvandyken closed 1 year ago

pvandyken commented 1 year ago

Python Version: 3.10 nda-tools Version: 0.2.22

The following error prints out after attempting to download a non-existent package (I was mistakenly using the package name rather than the id):

>>> downloadcmd -dp foobar -d some_dir --workerThreads 1

Running NDATools Version 0.2.22
-u/--username argument not provided. Using default value of 'pvandyk2' which was saved in /home/.../.NDATools/settings.cfg

Getting Package Information...
Traceback (most recent call last):
  File "/home/.../.local/bin/downloadcmd", line 8, in <module>
    sys.exit(main())
  File "/home/.../nda-tools/lib/python3.10/site-packages/NDATools/clientscripts/downloadcmd.py", line 195, in main
    s3Download.start()
  File "/home/.../nda-tools/lib/python3.10/site-packages/NDATools/Download.py", line 183, in start
    package_resource = self.get_package_info()
  File "/home/.../nda-tools/lib/python3.10/site-packages/NDATools/Download.py", line 1011, in get_package_info
    tmp = get_request(url, auth=self.auth, deserialize_handler=DeserializeHandler.none)
  File "/home/.../nda-tools/lib/python3.10/site-packages/NDATools/Utils.py", line 269, in get_request
    return _send_prepared_request(req.prepare(), timeout=timeout, deserialize_handler=deserialize_handler, error_handler=error_handler)
  File "/home/.../nda-tools/lib/python3.10/site-packages/NDATools/Utils.py", line 240, in _retry
    tmp = func(*args, **kwargs)
  File "/home/.../nda-tools/lib/python3.10/site-packages/NDATools/Utils.py", line 263, in _send_prepared_request
    error_handler(tmp)
  File "/home/.../nda-tools/lib/python3.10/site-packages/NDATools/Utils.py", line 71, in print_and_exit
    message = r.json()['message']
KeyError: 'message'

If I print out r.json() in the final function in the trace (print_and_exit), I get the following:

{'timestamp': 1673456604119, 'status': 400, 'error': 'Bad Request', 'path': '/api/package/foobar'}

These 400 errors should be caught and lead to some requested package does not exist error.

pvandyken commented 1 year ago

Ideally, since I presume the id needs to be a number, there should be some validation of the value passed to -dp ensuring it looks like a number, printing some sort of -dp must be a number error when invalid.

gregmagdits commented 1 year ago

agreed. Ill create an internal work ticket and try and get it in the next release

gregmagdits commented 1 year ago

Latest release (0.2.23) includes the validation for the -dp arg along with an updated description in the output of the --help command to clarify the command syntax. Closing issue