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

Implement global except hook, refactor current exceptions handling #73

Closed
1 task done
rszamszur opened this issue Apr 19, 2022 · 1 comment · Fixed by #70
Closed
1 task done

Implement global except hook, refactor current exceptions handling #73

rszamszur opened this issue Apr 19, 2022 · 1 comment · Fixed by #70
Assignees
Labels
enhancement New feature or request refactor Related to major code refactoring/reorganisation
Milestone

Comments

@rszamszur
Copy link
Member

  • I have searched the issues of this repo and believe that this is not a duplicate.

Feature Request

Implement a global except hook for unhandled exceptions that will log exception + debug info to make issuing defects easier.

Something like that:

$ fastapi-mvc run
[INFO] Executing shell command.
[WARNING] Activated virtual env detected.
[ERROR] Unhandled exception occurred during RunTime.
Traceback (most recent call last):
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/bin/fastapi-mvc", line 5, in <module>
    cli()
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/lib/python3.9/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/lib/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/fastapi_mvc/cli/run.py", line 70, in run
    invoker.execute()
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/fastapi_mvc/commands/invoker.py", line 42, in execute
    command.execute()
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/fastapi_mvc/commands/run_shell.py", line 49, in execute
    ShellUtils.run_shell(
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/fastapi_mvc/utils/shell.py", line 91, in run_shell
    process = subprocess.run(
  File "/nix/store/y3inmdhijqkb4qj36yphj4cbllljhqzz-python3-3.9.6/lib/python3.9/subprocess.py", line 505, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/nix/store/y3inmdhijqkb4qj36yphj4cbllljhqzz-python3-3.9.6/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/nix/store/y3inmdhijqkb4qj36yphj4cbllljhqzz-python3-3.9.6/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'poetry'
[INFO] Feel free to raise an issue here: https://github.com/rszamszur/fastapi-mvc/issues/new/choose
    Environment:
    Python version: 3.9.6
    Operating System: Linux-5.10.106-x86_64-with-glibc2.33
    fastapi-mvc version: 0.10.0

This feature might require some refactoring in project exceptions.

@rszamszur rszamszur added enhancement New feature or request refactor Related to major code refactoring/reorganisation labels Apr 19, 2022
@rszamszur rszamszur self-assigned this Apr 19, 2022
@rszamszur rszamszur added this to the 0.11.0 milestone Apr 19, 2022
@rszamszur
Copy link
Member Author

On verbose excepthook will preformat issues template for convenience. Otherwise, it'll just print traceback with msg.

Final result:

$ fastapi-mvc run
[WARNING] Activated virtual env detected.
[ERROR] Unhandled exception occurred during RunTime.
Traceback (most recent call last):
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/bin/fastapi-mvc", line 5, in <module>
    cli()
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/lib/python3.9/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/lib/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/fastapi_mvc/cli/run.py", line 37, in run
    borg.require_installed()
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/fastapi_mvc/borg.py", line 130, in require_installed
    ShellUtils.run_shell(
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/fastapi_mvc/utils/shell.py", line 91, in run_shell
    process = subprocess.run(
  File "/nix/store/y3inmdhijqkb4qj36yphj4cbllljhqzz-python3-3.9.6/lib/python3.9/subprocess.py", line 505, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/nix/store/y3inmdhijqkb4qj36yphj4cbllljhqzz-python3-3.9.6/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/nix/store/y3inmdhijqkb4qj36yphj4cbllljhqzz-python3-3.9.6/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'poetry'
[INFO] Help improve fastapi-mvc :)

It does not have to be a defect immediately. But if you think this should not
happen or it would make a nice feature, feel free to create an issue:
https://github.com/rszamszur/fastapi-mvc/issues/new

Hint: Running with `--verbose` will preformat markdown issues template for you:
fastapi-mvc --verbose run


(.venv) 
$ fastapi-mvc --verbose run
[2022-04-22 20:50:29 +0200] [Borg:48] [DEBUG] Initialize first Borg class object instance.
[2022-04-22 20:50:29 +0200] [Invoker:23] [DEBUG] Initialize Invoker class object instance.
[2022-04-22 20:50:29 +0200] [IniParser:29] [DEBUG] Initialize fastapi-mvc.ini parser.
[2022-04-22 20:50:29 +0200] [IniParser:37] [DEBUG] Begin parsing: /tmp/test-app/fastapi-mvc.ini
[2022-04-22 20:50:29 +0200] [Borg:121] [DEBUG] Verifying if fastapi-mvc project is installed.
[2022-04-22 20:50:29 +0200] [fastapi_mvc.utils.shell:75] [DEBUG] Run shell command: ['poetry', 'run', 'test-app', '--help'] under path: /tmp/test-app
[2022-04-22 20:50:29 +0200] [fastapi_mvc.utils.shell:83] [WARNING] Activated virtual env detected.
[2022-04-22 20:50:29 +0200] [GlobalExceptHook:73] [ERROR] Unhandled exception occurred during RunTime.
Traceback (most recent call last):
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/bin/fastapi-mvc", line 5, in <module>
    cli()
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/lib/python3.9/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/lib/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/fastapi_mvc/cli/run.py", line 37, in run
    borg.require_installed()
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/fastapi_mvc/borg.py", line 130, in require_installed
    ShellUtils.run_shell(
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/fastapi_mvc/utils/shell.py", line 91, in run_shell
    process = subprocess.run(
  File "/nix/store/y3inmdhijqkb4qj36yphj4cbllljhqzz-python3-3.9.6/lib/python3.9/subprocess.py", line 505, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/nix/store/y3inmdhijqkb4qj36yphj4cbllljhqzz-python3-3.9.6/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/nix/store/y3inmdhijqkb4qj36yphj4cbllljhqzz-python3-3.9.6/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'poetry'
[2022-04-22 20:50:29 +0200] [GlobalExceptHook:79] [INFO] Help improve fastapi-mvc :)

It does not have to be a defect immediately. But if you think this should not
happen or it would make a nice feature, feel free to create an issue:
https://github.com/rszamszur/fastapi-mvc/issues/new

I've formated copy-paste markdown with details for you to make things easier.
However, add/edit whatever you see fit.

-----------------------------------------------------------------------------

**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
\```shell
Traceback (most recent call last):
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/bin/fastapi-mvc", line 5, in <module>
    cli()
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/lib/python3.9/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/lib/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/.venv/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/fastapi_mvc/cli/run.py", line 37, in run
    borg.require_installed()
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/fastapi_mvc/borg.py", line 130, in require_installed
    ShellUtils.run_shell(
  File "/home/rszamszur/repos/gh/rszamszur/fastapi-mvc/fastapi_mvc/utils/shell.py", line 91, in run_shell
    process = subprocess.run(
  File "/nix/store/y3inmdhijqkb4qj36yphj4cbllljhqzz-python3-3.9.6/lib/python3.9/subprocess.py", line 505, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/nix/store/y3inmdhijqkb4qj36yphj4cbllljhqzz-python3-3.9.6/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/nix/store/y3inmdhijqkb4qj36yphj4cbllljhqzz-python3-3.9.6/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'poetry'

\```

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->

**To Reproduce**
<!-- Steps to reproduce the behavior. -->
\```shell
fastapi-mvc --verbose run
\```

**Environment**
* Python version: `3.9.6`
* Operating System: `Linux-5.10.106-x86_64-with-glibc2.33`
* fastapi-mvc version: `0.10.0`

**Additional context**
<!-- Add any other context about the problem here. -->

@rszamszur rszamszur changed the title Implement global except hook, refactor current project exceptions Implement global except hook, refactor current exceptions handling Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactor Related to major code refactoring/reorganisation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant