{"id":27156665,"url":"https://github.com/definetlynotai/exceptionhandler","last_synced_at":"2025-04-10T02:14:51.116Z","repository":{"id":286816957,"uuid":"962648947","full_name":"DefinetlyNotAI/ExceptionHandler","owner":"DefinetlyNotAI","description":"A Python-based exception handling utility that provides customizable exception messages, formatting, and behavior.","archived":false,"fork":false,"pushed_at":"2025-04-08T13:36:54.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-08T14:35:40.131Z","etag":null,"topics":["custom","customization","error-handling","exception","exception-handling","library","powerful","python","simple"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DefinetlyNotAI.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-04-08T13:20:23.000Z","updated_at":"2025-04-08T13:36:58.000Z","dependencies_parsed_at":"2025-04-08T14:47:54.901Z","dependency_job_id":null,"html_url":"https://github.com/DefinetlyNotAI/ExceptionHandler","commit_stats":null,"previous_names":["definetlynotai/exceptionhandler"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DefinetlyNotAI%2FExceptionHandler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DefinetlyNotAI%2FExceptionHandler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DefinetlyNotAI%2FExceptionHandler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DefinetlyNotAI%2FExceptionHandler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DefinetlyNotAI","download_url":"https://codeload.github.com/DefinetlyNotAI/ExceptionHandler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247924077,"owners_count":21019113,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["custom","customization","error-handling","exception","exception-handling","library","powerful","python","simple"],"created_at":"2025-04-08T20:32:02.643Z","updated_at":"2025-04-08T20:33:36.116Z","avatar_url":"https://github.com/DefinetlyNotAI.png","language":"Python","readme":"# Exception Handler\n\nA Python-based exception handling utility that provides customizable exception messages,\nformatting, and behavior. \n\nThis project allows developers to handle exceptions with enhanced readability and flexibility.\nIt is designed to be easy to use and integrate into existing projects, \nproviding a consistent way to manage exceptions across your codebase.\n\n## Features\n\n- **Customizable Exception Handling**: Configure global and local exception handling settings.\n- **Traceback and Line Number**: Optionally include traceback and line numbers in exception messages.\n- **Timestamp Support**: Add timestamps to exception messages with customizable formats.\n- **Color and Format Customization**: Customize colors and text formats for exception messages, tracebacks, and timestamps.\n- **Global and Local Settings**: Override global settings with local configurations for specific exceptions.\n- **Script Exit Control**: Control whether the script exits after handling an exception.\n- **Return or Print Messages**: Choose to return exception messages as strings or print them directly.\n\n## Installation\n\nClone the repository and ensure you have Python installed.\nRecommended to use Python 3.11 or higher.\n\n```bash\ngit clone https://github.com/DefinetlyNotAI/ExceptionHandler.git\ncd ExceptionHandler\n```\n\n## Usage\n\n### Initialize the Handler\n\n```python\nfrom exception import Handler, Colors, Format\n\n# Initialize the Handler with custom settings - These are global settings\n# NOTE: return_string_rather_than_print has priority over exit_script both locally and globally!\nhandler = Handler(\n    show_line=True,  # Show the line number where the exception occurred\n    trace=True,  # Include the traceback in the output\n    use_timestamp=True,  # Add a timestamp to the exception message\n    exit_script=True,  # Exit the script after handling the exception\n    return_string_rather_than_print=True\n    # Return the message instead of printing it,\n    # if True it will override/ignore exit_script\n)\n\n# Customize the formatter\n# NOTE: Specific settings always the defaults,\n#       example if message_color is set it will override the main_color for the message part,\nhandler.formatter(\n    main_color=Colors.RED,  # Set the main color to red\n    message_color=Colors.YELLOW,  # Set the message color to yellow\n    trace_color=Colors.CYAN,  # Set the traceback color to cyan\n    timestamps_color=Colors.GREEN,  # Set the timestamp color to green\n    main_format=Format.BOLD,  # Set the main format to bold\n    message_format=Format.UNDERLINE,  # Underline the message text\n    trace_format=Format.DIM,  # Dim the traceback text\n    timestamps_format=Format.BLINK,  # Blink the timestamp text\n    datetime_format=\"%d-%m-%Y %H:%M:%S\"  # Customize the datetime format\n)\n```\n\n### Example Function\n\n```python\n# Bare Minimum\nfrom exception import Handler\n\nhandler = Handler()  # Use default settings\n\ndef divide_numbers(a, b):\n    try:\n        return a / b\n    except Exception as e:\n        # Note: You can just use handler.exception() or handler.exception(msg=e) to rely on global settings\n        handler.exception(\n            # These are local settings, if they are different from the global, they take priority\n            # so they will override the global settings only for this case.\n            msg=e,  # Detailed exception message, can be a custom string\n            exit_script=True,  # Exit the script after handling the exception\n            quit_code=1,  # Exit code to use when exiting the script, defaults to 1\n            return_string_rather_than_print=False  # Return the message instead of printing it\n            # NOTE: If return_string_rather_than_print is set to True globally,\n            #       and you want to locally quit for this singular case,\n            #       then you HAVE TO explicitly set it to False here.\n        )\n\ndivide_numbers(10, 0)\n```\n\n## Customization\n\n- **Global Settings**: Set during `Handler` initialization.\n- **Local Settings**: Override global settings in the `exception` method.\n- **Formatter**: Customize colors and formats using the `formatter` method.\n\nCheck the [`example.py`](example.py) file for a proper example.\n\n### Override priority\n\n- Local settings take precedence over global settings.\n  - If both global and local settings are provided, the local settings will override the global ones.\n  - To use the global settings, simply call `handler.exception()`/`handler.exception(msg=e)`.\n    - Any settings you want to override for this specific use case can be passed as arguments.\n- `return_string_rather_than_print` has priority over `exit_script` both locally and globally.\n  - If `return_string_rather_than_print` is set to `True` globally, and you want to locally quit for this singular case, then you HAVE TO explicitly set it to `False` in the local settings.\n\n### Modify Colors, Format or Messages\n\nIf you want to modify the DataType for format's or colors ANSI, you can do so by modifying the `Format` and `Colors` classes in the [`exception.py`](exception/colors.py) file.\n\nIf you want to add/remove Messages from the dictionary, you can do so by modifying the `Messages` class in the [`messages.py`](exception/messages.py) file.\n\n## Dependencies\n\n- Datetime\n\n## License\n\nThis project is licensed under the MIT License. See the [`LICENSE`](LICENSE) file for details.\n\n## Contributing\n\nContributions are welcome! Please fork the repository and submit a pull request.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdefinetlynotai%2Fexceptionhandler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdefinetlynotai%2Fexceptionhandler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdefinetlynotai%2Fexceptionhandler/lists"}