Skip to content

Improve handler loading error message #341

Closed
@deliahu

Description

@deliahu

Description

When a handler cannot be loaded, e.g. due to a syntax error in the python file, the error message is unclear (and potentially misleading).

In the case below, the handler file was called sklearn.py, and there was an error in the file (json was being used without being imported). The only log that was presented in cx logs was:

error: api sklearn: request_handler handlers/sklearn.py: unable to load python module sklearn"

Perhaps this would be less confusing if the error message was:

error: api sklearn: unable to load handlers/sklearn.py"

Full stack trace:

Looking in links: /wheelhouse/requirements.txt
Collecting numpy==1.16.4 (from -r /requirements.txt (line 1))
Collecting sklearn (from -r /requirements.txt (line 2))
Collecting scikit-learn (from sklearn->-r /requirements.txt (line 2))
Collecting scipy>=0.17.0 (from scikit-learn->sklearn->-r /requirements.txt (line 2))
Collecting joblib>=0.11 (from scikit-learn->sklearn->-r /requirements.txt (line 2))
Installing collected packages: numpy, scipy, joblib, scikit-learn, sklearn
  Found existing installation: numpy 1.17.0
    Uninstalling numpy-1.17.0:
      Successfully uninstalled numpy-1.17.0
Successfully installed joblib-0.13.2 numpy-1.16.4 scikit-learn-0.21.3 scipy-1.3.1 sklearn-0.0
ERROR:cortex:error: api sklearn: request_handler handlers/sklearn.py: unable to load python module sklearn
ERROR:cortex:An error occured starting the api, see `cx logs -v api sklearn` for more details
Traceback (most recent call last):
  File "/src/cortex/lib/context.py", line 180, in load_module
    impl = imp.load_source(full_module_name, impl_path)
  File "/usr/lib/python3.5/imp.py", line 172, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 693, in _load
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/mnt/context/request_handler_sklearn.py", line 9, in <module>
    scalars = json.loads(scalars_obj["Body"].read().decode("utf-8"))
NameError: name 'json' is not defined

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/src/cortex/onnx_serve/api.py", line 241, in start
    local_cache["request_handler"] = ctx.get_request_handler_impl(api["name"])
  File "/src/cortex/lib/context.py", line 280, in get_request_handler_impl
    module_prefix, api["name"], api["request_handler_impl_key"]
  File "/src/cortex/lib/context.py", line 182, in load_module
    raise UserException("unable to load python module " + module_name) from e
cortex.lib.exceptions.UserException: error: api sklearn: request_handler handlers/sklearn.py: unable to load python module sklearn

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions