dnanexus/dx-toolkit

get_download_url should never raise SystemExit

Opened this issue · 0 comments

Raising a systemexit is really problematic because hard to catch. Really should throw an exception that the dx CLI tool converts to a systemexit.

How to reproduce:

  1. Get file ID and project ID that you do not have access to
  2. dxpy.DXFile(file_id, project_id).get_download_url()
home/deploy/app/config/2021-07-01.005634_010aac/repo/.venv/lib/python3.6/site-packages/dxpy/cli/__init__.py in try_call(func, *args, **kwargs)
     35     try:
---> 36         return func(*args, **kwargs)
     37     except:

/home/deploy/app/config/2021-07-01.005634_010aac/repo/.venv/lib/python3.6/site-packages/dxpy/__init__.py in DXHTTPRequest(resource, data, method, headers, auth, timeout, use_compression, jsonify_data, want_full_response, decode_response_body, prepend_srv, session_handler, max_retries, always_retry, **kwargs)
    681                         raise exceptions.HTTPError(response.status, content)
--> 682                     raise error_class(content, response.status, time_started, req_id)
    683                 else:

PermissionDenied: VIEW permission required in project-FbPGg5j06GZ3Ybx4KY7100g5 to perform this action, code 401. Request Time=1625101595.2516103, Request ID=1625101595488-323642

During handling of the above exception, another exception occurred:

SystemExit                                Traceback (most recent call last)
<ipython-input-12-cf196c92df9b> in <module>()
----> 1 dxf.get_download_url()

/home/deploy/app/config/2021-07-01.005634_010aac/repo/.venv/lib/python3.6/site-packages/dxpy/bindings/dxfile.py in get_download_url(self, duration, preauthenticated, filename, project, **kwargs)
    778         if project is None and 'DX_JOB_ID' not in os.environ:
    779             project_from_handler = self.get_proj_id()
--> 780             if project_from_handler and object_exists_in_project(self.get_id(), project_from_handler):
    781                 project = project_from_handler
    782

/home/deploy/app/config/2021-07-01.005634_010aac/repo/.venv/lib/python3.6/site-packages/dxpy/utils/resolver.py in object_exists_in_project(obj_id, proj_id)
    209     if not is_container_id(proj_id):
    210         raise ValueError('Expected %r to be a container ID' % (proj_id,))
--> 211     return try_call(dxpy.DXHTTPRequest, '/' + obj_id + '/describe', {'project': proj_id})['project'] == proj_id
    212
    213

/home/deploy/app/config/2021-07-01.005634_010aac/repo/.venv/lib/python3.6/site-packages/dxpy/cli/__init__.py in try_call(func, *args, **kwargs)
     36         return func(*args, **kwargs)
     37     except:
---> 38         try_call_err_exit()
     39
     40 def prompt_for_yn(prompt_str, default=None):

/home/deploy/app/config/2021-07-01.005634_010aac/repo/.venv/lib/python3.6/site-packages/dxpy/cli/__init__.py in try_call_err_exit()
     30
     31 def try_call_err_exit():
---> 32     err_exit(expected_exceptions=default_expected_exceptions + (DXError,))
     33
     34 def try_call(func, *args, **kwargs):

/home/deploy/app/config/2021-07-01.005634_010aac/repo/.venv/lib/python3.6/site-packages/dxpy/exceptions.py in err_exit(message, code, expected_exceptions, arg_parser, ignore_sigpipe, exception)
    259         raise exc
    260     elif isinstance(exc, expected_exceptions):
--> 261         exit_with_exc_info(EXPECTED_ERR_EXIT_STATUS, message, print_tb=dxpy._DEBUG > 0, exception=exception)
    262     elif ignore_sigpipe and isinstance(exc, IOError) and getattr(exc, 'errno', None) == errno.EPIPE:
    263         if dxpy._DEBUG > 0:

/home/deploy/app/config/2021-07-01.005634_010aac/repo/.venv/lib/python3.6/site-packages/dxpy/exceptions.py in exit_with_exc_info(code, message, print_tb, exception)
    218     if message != '' and not message.endswith('\n'):
    219         sys.stderr.write('\n')
--> 220     sys.exit(code)
    221
    222 network_exceptions = (requests.packages.urllib3.exceptions.ProtocolError,