mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 11:19:56 +00:00
### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> The existing Exceptions structure was very much inspired by dotnet, this is now replaced with a pythonic implementations. This means all Exceptions derive from KernelException and then specialise for different purposes. Closes #2194 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> Added folder for all exception types, all can be imported through `from semantic_kernel.exceptions import ...` no need for a user to know which file the relevant one is in, but keeps things tidy for developers. Removed old KernelException, added back subtypes for the errorcodes. Went through everything to make sure the `raise ... from exc` pattern is used as much as possible as that returns a better stacktrace. ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄
45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
|
|
# Even though there is no strict separation between errors and exceptions in Python, it is a good practice to use:
|
|
# - Exceptions for exceptional conditions that a reasonable application may wish to catch.
|
|
# - Errors for exceptional conditions that are not reasonable to catch.
|
|
# for instance syntax errors in a template should be called ...Error,
|
|
# while rendering of the same template should raise an ...Exception.
|
|
# every error should derive from KernelException (including errors)
|
|
# all raised exceptions should use the raise ... from exc syntax to preserve the original traceback
|
|
|
|
|
|
class KernelException(Exception):
|
|
pass
|
|
|
|
|
|
class KernelServiceNotFoundError(KernelException):
|
|
pass
|
|
|
|
|
|
class KernelPluginNotFoundError(KernelException):
|
|
pass
|
|
|
|
|
|
class KernelFunctionNotFoundError(KernelException):
|
|
pass
|
|
|
|
|
|
class KernelFunctionAlreadyExistsError(KernelException):
|
|
pass
|
|
|
|
|
|
class KernelInvokeException(KernelException):
|
|
pass
|
|
|
|
|
|
__all__ = [
|
|
"KernelException",
|
|
"KernelFunctionAlreadyExistsError",
|
|
"KernelFunctionNotFoundError",
|
|
"KernelInvokeException",
|
|
"KernelPluginNotFoundError",
|
|
"KernelServiceNotFoundError",
|
|
]
|