mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 02:19:06 +00:00
### Motivation and Context In an effort to make the Python port more idiomatic, let's remove the `Verify` class and the `./diagnostics` sub-module. There are many more follow-on tasks to do here, but this is a good start (and already a large enough change). ### Description This PR does the following: 1. Removes the `Verify` class, and re-writes all instances of `Verify.*` 2. Adds a `validation.py` in the `./utils` sub-module to hand some of the more complex cases from `Verify` (checking that skills/functions/and function params have valid names) 3. Removes the rest of the `./diagnostics` sub-module (w/ a longer-term goal of removing all/most of our custom exception classes and, instead, using appropriate built-in error classes)
57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
# Copyright (c) Microsoft. All rights reserved.
|
|
|
|
from enum import Enum
|
|
from typing import Optional
|
|
|
|
|
|
class KernelException(Exception):
|
|
class ErrorCodes(Enum):
|
|
# Unknown error.
|
|
UnknownError = -1
|
|
# Invalid function description.
|
|
InvalidFunctionDescription = 0
|
|
# Function overload not supported.
|
|
FunctionOverloadNotSupported = 1
|
|
# Function not available.
|
|
FunctionNotAvailable = 2
|
|
# Function type not supported.
|
|
FunctionTypeNotSupported = 3
|
|
# Invalid function type.
|
|
InvalidFunctionType = 4
|
|
# Invalid backend configuration.
|
|
InvalidBackendConfiguration = 5
|
|
# Backend not found.
|
|
BackendNotFound = 6
|
|
# Skill collection not set.
|
|
SkillCollectionNotSet = 7
|
|
# Ambiguous implementation.
|
|
AmbiguousImplementation = 8
|
|
|
|
# The error code.
|
|
_error_code: ErrorCodes
|
|
|
|
def __init__(
|
|
self,
|
|
error_code: ErrorCodes,
|
|
message: str,
|
|
inner_exception: Optional[Exception] = None,
|
|
) -> None:
|
|
"""Initializes a new instance of the KernelError class.
|
|
|
|
Arguments:
|
|
error_code {ErrorCodes} -- The error code.
|
|
message {str} -- The error message.
|
|
inner_exception {Exception} -- The inner exception.
|
|
"""
|
|
super().__init__(error_code, message, inner_exception)
|
|
self._error_code = error_code
|
|
|
|
@property
|
|
def error_code(self) -> ErrorCodes:
|
|
"""Gets the error code.
|
|
|
|
Returns:
|
|
ErrorCodes -- The error code.
|
|
"""
|
|
return self._error_code
|