aws / aws-lambda-python-runtime-interface-client

Apache License 2.0
258 stars 73 forks source link

Improve Exception Output for run with Missing Handler #70

Closed jackcasey-visier closed 2 years ago

jackcasey-visier commented 2 years ago

Summary

This change improves the error handling when running awslambdaric without a handler. Currently, the exception thrown is fairly non-specific:

python -m awslambdaric

Traceback (most recent call last):
  File "python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "awslambdaric/__main__.py", line 20, in <module>
    main(sys.argv)
  File "awslambdaric/__main__.py", line 13, in main
    handler = args[1]
IndexError: list index out of range

The changes make the output a bit more human friendly 😄 :

python -m awslambdaric

Traceback (most recent call last):
  File "python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "awslambdaric/__main__.py", line 25, in <module>
    main(sys.argv)
  File "awslambdaric/__main__.py", line 17, in main
    raise ValueError("Handler not set")
ValueError: Handler not set

Even with the changes in place the module exists with an unhandled exception in the same way. We may want to wrap this to provide a more clean exit 😅

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

jackcasey-visier commented 2 years ago

@zsombor-balogh My pleasure!

jackcasey-visier commented 2 years ago

@zsombor-balogh @carlzogh Friendly poke :)

Just curious, is there anything I can do to help move this forward? Is there testing that needs to be accomplished?

Thanks!

zsombor-balogh commented 2 years ago

@zsombor-balogh @carlzogh Friendly poke :)

Just curious, is there anything I can do to help move this forward? Is there testing that needs to be accomplished?

Thanks!

Apologies for the delay, merged it now!