Merge branch 'fix/chore-fix' into dev/plugin-deploy

pull/12372/head
Yeuoly 1 year ago
commit 1858e523f1
No known key found for this signature in database
GPG Key ID: A66E7E320FB19F61

@ -108,7 +108,6 @@ class PluginDaemonError(BaseModel):
error_type: str error_type: str
message: str message: str
args: Optional[dict] = None
class PluginDaemonInnerError(Exception): class PluginDaemonInnerError(Exception):

@ -2,7 +2,7 @@ import inspect
import json import json
import logging import logging
from collections.abc import Callable, Generator from collections.abc import Callable, Generator
from typing import Optional, TypeVar from typing import TypeVar
import requests import requests
from pydantic import BaseModel from pydantic import BaseModel
@ -16,12 +16,14 @@ from core.model_runtime.errors.invoke import (
InvokeRateLimitError, InvokeRateLimitError,
InvokeServerUnavailableError, InvokeServerUnavailableError,
) )
from core.model_runtime.errors.validate import CredentialsValidateFailedError
from core.plugin.entities.plugin_daemon import PluginDaemonBasicResponse, PluginDaemonError, PluginDaemonInnerError from core.plugin.entities.plugin_daemon import PluginDaemonBasicResponse, PluginDaemonError, PluginDaemonInnerError
from core.plugin.manager.exc import ( from core.plugin.manager.exc import (
PluginDaemonBadRequestError, PluginDaemonBadRequestError,
PluginDaemonInternalServerError, PluginDaemonInternalServerError,
PluginDaemonNotFoundError, PluginDaemonNotFoundError,
PluginDaemonUnauthorizedError, PluginDaemonUnauthorizedError,
PluginInvokeError,
PluginPermissionDeniedError, PluginPermissionDeniedError,
PluginUniqueIdentifierError, PluginUniqueIdentifierError,
) )
@ -144,7 +146,7 @@ class BasePluginManager:
except Exception as e: except Exception as e:
raise ValueError(f"{rep.message}, code: {rep.code}") raise ValueError(f"{rep.message}, code: {rep.code}")
self._handle_plugin_daemon_error(error.error_type, error.message, error.args) self._handle_plugin_daemon_error(error.error_type, error.message)
if rep.data is None: if rep.data is None:
frame = inspect.currentframe() frame = inspect.currentframe()
raise ValueError(f"got empty data from plugin daemon: {frame.f_lineno if frame else 'unknown'}") raise ValueError(f"got empty data from plugin daemon: {frame.f_lineno if frame else 'unknown'}")
@ -183,32 +185,39 @@ class BasePluginManager:
except Exception as e: except Exception as e:
raise PluginDaemonInnerError(code=rep.code, message=rep.message) raise PluginDaemonInnerError(code=rep.code, message=rep.message)
self._handle_plugin_daemon_error(error.error_type, error.message, error.args) self._handle_plugin_daemon_error(error.error_type, error.message)
raise ValueError(f"plugin daemon: {rep.message}, code: {rep.code}") raise ValueError(f"plugin daemon: {rep.message}, code: {rep.code}")
if rep.data is None: if rep.data is None:
frame = inspect.currentframe() frame = inspect.currentframe()
raise ValueError(f"got empty data from plugin daemon: {frame.f_lineno if frame else 'unknown'}") raise ValueError(f"got empty data from plugin daemon: {frame.f_lineno if frame else 'unknown'}")
yield rep.data yield rep.data
def _handle_plugin_daemon_error(self, error_type: str, message: str, args: Optional[dict] = None): def _handle_plugin_daemon_error(self, error_type: str, message: str):
""" """
handle the error from plugin daemon handle the error from plugin daemon
""" """
args = args or {}
match error_type: match error_type:
case PluginDaemonInnerError.__name__: case PluginDaemonInnerError.__name__:
raise PluginDaemonInnerError(code=-500, message=message) raise PluginDaemonInnerError(code=-500, message=message)
case InvokeRateLimitError.__name__: case PluginInvokeError.__name__:
raise InvokeRateLimitError(description=args.get("description")) error_object = json.loads(message)
case InvokeAuthorizationError.__name__: invoke_error_type = error_object.get("error_type")
raise InvokeAuthorizationError(description=args.get("description")) args = error_object.get("args")
case InvokeBadRequestError.__name__: match invoke_error_type:
raise InvokeBadRequestError(description=args.get("description")) case InvokeRateLimitError.__name__:
case InvokeConnectionError.__name__: raise InvokeRateLimitError(description=args.get("description"))
raise InvokeConnectionError(description=args.get("description")) case InvokeAuthorizationError.__name__:
case InvokeServerUnavailableError.__name__: raise InvokeAuthorizationError(description=args.get("description"))
raise InvokeServerUnavailableError(description=args.get("description")) case InvokeBadRequestError.__name__:
raise InvokeBadRequestError(description=args.get("description"))
case InvokeConnectionError.__name__:
raise InvokeConnectionError(description=args.get("description"))
case InvokeServerUnavailableError.__name__:
raise InvokeServerUnavailableError(description=args.get("description"))
case CredentialsValidateFailedError.__name__:
raise CredentialsValidateFailedError(error_object.get("message"))
case _:
raise PluginInvokeError(description=message)
case PluginDaemonInternalServerError.__name__: case PluginDaemonInternalServerError.__name__:
raise PluginDaemonInternalServerError(description=message) raise PluginDaemonInternalServerError(description=message)
case PluginDaemonBadRequestError.__name__: case PluginDaemonBadRequestError.__name__:
@ -222,4 +231,4 @@ class BasePluginManager:
case PluginPermissionDeniedError.__name__: case PluginPermissionDeniedError.__name__:
raise PluginPermissionDeniedError(description=message) raise PluginPermissionDeniedError(description=message)
case _: case _:
raise Exception(f"got unknown error from plugin daemon: {error_type}, message: {message}, args: {args}") raise Exception(f"got unknown error from plugin daemon: {error_type}, message: {message}")

@ -21,6 +21,10 @@ class PluginDaemonNotFoundError(PluginDaemonError):
description: str = "Not Found" description: str = "Not Found"
class PluginInvokeError(PluginDaemonError):
description: str = "Invoke Error"
class PluginUniqueIdentifierError(PluginDaemonError): class PluginUniqueIdentifierError(PluginDaemonError):
description: str = "Unique Identifier Error" description: str = "Unique Identifier Error"

@ -6,6 +6,7 @@ from configs import dify_config
from core.helper.position_helper import is_filtered from core.helper.position_helper import is_filtered
from core.model_runtime.utils.encoders import jsonable_encoder from core.model_runtime.utils.encoders import jsonable_encoder
from core.plugin.entities.plugin import GenericProviderID from core.plugin.entities.plugin import GenericProviderID
from core.plugin.manager.exc import PluginInvokeError
from core.tools.builtin_tool.providers._positions import BuiltinToolProviderSort from core.tools.builtin_tool.providers._positions import BuiltinToolProviderSort
from core.tools.entities.api_entities import ToolApiEntity, ToolProviderApiEntity from core.tools.entities.api_entities import ToolApiEntity, ToolProviderApiEntity
from core.tools.errors import ToolNotFoundError, ToolProviderCredentialValidationError, ToolProviderNotFoundError from core.tools.errors import ToolNotFoundError, ToolProviderCredentialValidationError, ToolProviderNotFoundError
@ -137,7 +138,12 @@ class BuiltinToolManageService:
provider_controller.validate_credentials(user_id, credentials) provider_controller.validate_credentials(user_id, credentials)
# encrypt credentials # encrypt credentials
credentials = tool_configuration.encrypt(credentials) credentials = tool_configuration.encrypt(credentials)
except (ToolProviderNotFoundError, ToolNotFoundError, ToolProviderCredentialValidationError) as e: except (
PluginInvokeError,
ToolProviderNotFoundError,
ToolNotFoundError,
ToolProviderCredentialValidationError,
) as e:
raise ValueError(str(e)) raise ValueError(str(e))
if provider is None: if provider is None:

Loading…
Cancel
Save