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

Add exception_handler #333

Merged
merged 1 commit into from
May 14, 2024
Merged

Conversation

jkroepke
Copy link
Contributor

@jkroepke jkroepke commented Mar 7, 2024

From https://stackoverflow.com/questions/6234405/logging-uncaught-exceptions-in-python

Before:

Traceback (most recent call last):
  File "/app/sidecar.py", line 170, in <module>
    main()
    ~~~~^^
  File "/app/sidecar.py", line 81, in main
    _initialize_kubeclient_configuration()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/app/sidecar.py", line 150, in _initialize_kubeclient_configuration
    config.load_incluster_config()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/app/.venv/lib/python3.13/site-packages/kubernetes/config/incluster_config.py", line 121, in load_incluster_config
    try_refresh_token=try_refresh_token).load_and_set(client_configuration)
                                         ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.13/site-packages/kubernetes/config/incluster_config.py", line 54, in load_and_set
    self._load_config()
    ~~~~~~~~~~~~~~~~~^^
  File "/app/.venv/lib/python3.13/site-packages/kubernetes/config/incluster_config.py", line 62, in _load_config
    raise ConfigException("Service host/port is not set.")
kubernetes.config.config_exception.ConfigException: Service host/port is not set.

After:

{"time": "2024-03-17T09:43:23.667112+00:00", "exc_info": "Traceback (most recent call last):\n  File \"/app/sidecar.py\", line 170, in <module>\n    main()\n    ~~~~^^\n  File \"/app/sidecar.py\", line 81, in main\n    _initialize_kubeclient_configuration()\n    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^\n  File \"/app/sidecar.py\", line 150, in _initialize_kubeclient_configuration\n    config.load_incluster_config()\n    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^\n  File \"/app/.venv/lib/python3.13/site-packages/kubernetes/config/incluster_config.py\", line 121, in load_incluster_config\n    try_refresh_token=try_refresh_token).load_and_set(client_configuration)\n                                         ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^\n  File \"/app/.venv/lib/python3.13/site-packages/kubernetes/config/incluster_config.py\", line 54, in load_and_set\n    self._load_config()\n    ~~~~~~~~~~~~~~~~~^^\n  File \"/app/.venv/lib/python3.13/site-packages/kubernetes/config/incluster_config.py\", line 62, in _load_config\n    raise ConfigException(\"Service host/port is not set.\")\nkubernetes.config.config_exception.ConfigException: Service host/port is not set.", "taskName": null, "msg": "ConfigException: Service host/port is not set.", "level": "ERROR"}

@jkroepke jkroepke force-pushed the exception_handler branch from fb65c1e to 17355cb Compare March 17, 2024 09:43
@jkroepke jkroepke marked this pull request as ready for review March 17, 2024 09:44
@ChristianGeie ChristianGeie added enhancement New feature or request python Pull requests that update Python code labels May 14, 2024
@ChristianGeie
Copy link
Collaborator

@jkroepke so that I understand this correctly: You want to use the sys.excepthook function to set a global exception handler for uncaught exceptions, so this funtion is called via the custom exception hook sys.excepthook = exception_handler whenever an uncaught exception occurs.

@jkroepke
Copy link
Contributor Author

Yes

@ChristianGeie
Copy link
Collaborator

thanks for confirming that. Meantime i extend the tests. pls rebase so i can trigger the workflow again.

@jkroepke jkroepke force-pushed the exception_handler branch from 17355cb to b919f1c Compare May 14, 2024 07:46
@jkroepke
Copy link
Contributor Author

Done

Copy link
Collaborator

@ChristianGeie ChristianGeie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ChristianGeie ChristianGeie merged commit 95da6e0 into kiwigrid:master May 14, 2024
10 checks passed
@jkroepke jkroepke deleted the exception_handler branch May 14, 2024 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request python Pull requests that update Python code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants