Skip to content

Commit 6ef1569

Browse files
fix: validate companion env vars before launch
1 parent a233025 commit 6ef1569

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

launcher.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
import signal
99
import shlex
10+
from pathlib import Path
1011
from dotenv import load_dotenv
1112
from agentevolver.utils.daemon import LaunchCommandWhenAbsent
1213

@@ -98,9 +99,32 @@ def parse_args():
9899
return parser.parse_args()
99100

100101

102+
def _require_service_env(service_name: str):
103+
"""Return (path, script) for the companion service, validating env vars."""
104+
env_prefix = service_name.upper()
105+
service_path = os.environ.get(f'{env_prefix}_PATH')
106+
service_script = os.environ.get(f'{env_prefix}_SCRIPT')
107+
missing = []
108+
if not service_path:
109+
missing.append(f'{env_prefix}_PATH')
110+
if not service_script:
111+
missing.append(f'{env_prefix}_SCRIPT')
112+
if missing:
113+
example_hint = ""
114+
example_env = Path("example.env")
115+
if example_env.exists():
116+
example_hint = (
117+
f" Copy the relevant entries from {example_env} into your .env file."
118+
)
119+
raise RuntimeError(
120+
f"Missing environment variable(s) required to launch '{service_name}': "
121+
f"{', '.join(missing)}.{example_hint}"
122+
)
123+
return service_path, service_script
124+
125+
101126
def pty_launch(service_name: str, success_std_string="Starting server on"):
102-
service_path = os.environ.get(f'{service_name.upper()}_PATH')
103-
service_script = os.environ.get(f'{service_name.upper()}_SCRIPT')
127+
service_path, service_script = _require_service_env(service_name)
104128
companion = LaunchCommandWhenAbsent(
105129
full_argument_list=[service_script],
106130
dir=service_path,
@@ -393,4 +417,4 @@ def main():
393417
sys.exit(1)
394418

395419
if __name__ == "__main__":
396-
main()
420+
main()

0 commit comments

Comments
 (0)