mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-07 01:41:17 +00:00
warn loading error by default (#5818)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import traceback
|
||||
import warnings
|
||||
from typing import Dict, Optional, Set, Tuple
|
||||
|
||||
from importlib_metadata import entry_points
|
||||
@@ -12,8 +13,10 @@ from pydantic import (
|
||||
from pydantic.functional_serializers import PlainSerializer
|
||||
from typing_extensions import Annotated
|
||||
|
||||
from openbb_core.app.model.abstract.warning import OpenBBWarning
|
||||
from openbb_core.app.model.extension import Extension
|
||||
from openbb_core.app.provider_interface import ProviderInterface
|
||||
from openbb_core.env import Env
|
||||
|
||||
|
||||
class LoadingError(Exception):
|
||||
@@ -64,8 +67,14 @@ class CredentialsLoader:
|
||||
for c in entry.credentials:
|
||||
self.credentials["obbject"].add(c)
|
||||
except Exception as e:
|
||||
traceback.print_exception(type(e), e, e.__traceback__)
|
||||
raise LoadingError(f"Invalid extension '{entry_point.name}'") from e
|
||||
msg = f"Error loading extension: {entry_point.name}\n"
|
||||
if Env().DEBUG_MODE:
|
||||
traceback.print_exception(type(e), e, e.__traceback__)
|
||||
raise LoadingError(msg + f"\033[91m{e}\033[0m") from e
|
||||
warnings.warn(
|
||||
message=msg,
|
||||
category=OpenBBWarning,
|
||||
)
|
||||
|
||||
def from_providers(self) -> None:
|
||||
"""Load credentials from providers"""
|
||||
|
||||
@@ -565,10 +565,13 @@ class RouterLoader:
|
||||
if isinstance(entry, Router):
|
||||
router.include_router(router=entry, prefix=f"/{entry_point.name}")
|
||||
except Exception as e:
|
||||
traceback.print_exception(type(e), e, e.__traceback__)
|
||||
raise LoadingError(
|
||||
f"Error loading extension: {entry_point.name}\n"
|
||||
f"\033[91m{e}\033[0m"
|
||||
msg = f"Error loading extension: {entry_point.name}\n"
|
||||
if Env().DEBUG_MODE:
|
||||
traceback.print_exception(type(e), e, e.__traceback__)
|
||||
raise LoadingError(msg + f"\033[91m{e}\033[0m") from e
|
||||
warnings.warn(
|
||||
message=msg,
|
||||
category=OpenBBWarning,
|
||||
)
|
||||
|
||||
return router
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
"""Provider Registry Module."""
|
||||
|
||||
import traceback
|
||||
import warnings
|
||||
from functools import lru_cache
|
||||
from typing import Dict
|
||||
|
||||
from importlib_metadata import entry_points
|
||||
|
||||
from openbb_core.app.model.abstract.warning import OpenBBWarning
|
||||
from openbb_core.env import Env
|
||||
from openbb_core.provider.abstract.provider import Provider
|
||||
|
||||
|
||||
@@ -40,9 +43,16 @@ class RegistryLoader:
|
||||
registry = Registry()
|
||||
for entry_point in sorted(entry_points(group="openbb_provider_extension")):
|
||||
try:
|
||||
registry.include_provider(provider=entry_point.load())
|
||||
entry = entry_point.load()
|
||||
if isinstance(entry, Provider):
|
||||
registry.include_provider(provider=entry)
|
||||
except Exception as e:
|
||||
traceback.print_exception(type(e), e, e.__traceback__)
|
||||
raise LoadingError(f"Invalid provider '{entry_point.name}': {e}") from e
|
||||
|
||||
msg = f"Error loading extension: {entry_point.name}\n"
|
||||
if Env().DEBUG_MODE:
|
||||
traceback.print_exception(type(e), e, e.__traceback__)
|
||||
raise LoadingError(msg + f"\033[91m{e}\033[0m") from e
|
||||
warnings.warn(
|
||||
message=msg,
|
||||
category=OpenBBWarning,
|
||||
)
|
||||
return registry
|
||||
|
||||
Reference in New Issue
Block a user