File tree Expand file tree Collapse file tree 3 files changed +13
-3
lines changed Expand file tree Collapse file tree 3 files changed +13
-3
lines changed Original file line number Diff line number Diff line change 1212from questionpy_sdk .constants import DEFAULT_STATE_STORAGE_PATH
1313from questionpy_sdk .watcher import Watcher
1414from questionpy_sdk .webserver import WebServer
15+ from questionpy_sdk .webserver .errors import EnvironmentVariablesMissingError
1516from questionpy_sdk .webserver .server import WebServerArgs
1617from questionpy_server .worker .impl .subprocess import SubprocessWorker
1718from questionpy_server .worker .impl .thread import ThreadWorker
@@ -94,4 +95,8 @@ def run(
9495 else :
9596 coro = async_run (webserver_args )
9697
97- asyncio .run (coro )
98+ try :
99+ asyncio .run (coro )
100+ except EnvironmentVariablesMissingError as e :
101+ msg = f"The following environment variables are required to run the package: { ', ' .join (e .missing )} "
102+ raise click .ClickException (msg ) from e
Original file line number Diff line number Diff line change @@ -36,6 +36,11 @@ class MissingAttemptDataError(MissingStateError):
3636 message = "The attempt data is missing."
3737
3838
39+ class EnvironmentVariablesMissingError (Exception ):
40+ def __init__ (self , missing : set [str ]) -> None :
41+ self .missing = missing
42+
43+
3944@dataclass (config = ConfigDict (use_attribute_docstrings = True ))
4045class DetailedServerError :
4146 """Represents a server-side error serialized for client display."""
Original file line number Diff line number Diff line change 2424from questionpy_server .worker .runtime .package_location import PackageLocation
2525
2626from .constants import API_PATH_PREFIX , USE_VITE_DEV_SERVER , WEBSERVER_KEY
27+ from .errors import EnvironmentVariablesMissingError
2728from .manifest import read_manifest
2829
2930log = logging .getLogger ("questionpy-sdk:web-server" )
@@ -63,8 +64,7 @@ async def __aenter__(self) -> Self:
6364 # Check if required environment variables are set
6465 requested_environment_variables = self ._manifest .environment_variables or set ()
6566 if missing_environment_variables := requested_environment_variables - os .environ .keys ():
66- msg = f"Required environment variables not set: { missing_environment_variables } "
67- raise ValueError (msg )
67+ raise EnvironmentVariablesMissingError (missing = missing_environment_variables )
6868
6969 # Assemble worker permissions
7070 permissions = CompletePackagePermissions ()
You can’t perform that action at this time.
0 commit comments