diff --git a/plain2code.py b/plain2code.py index b4e2cd7..904d496 100644 --- a/plain2code.py +++ b/plain2code.py @@ -17,7 +17,7 @@ from module_renderer import ModuleRenderer from plain2code_arguments import parse_arguments from plain2code_console import console -from plain2code_exceptions import PlainSyntaxError +from plain2code_exceptions import MissingAPIKey, PlainSyntaxError from plain2code_logger import ( CrashLogHandler, IndentedFormatter, @@ -208,6 +208,12 @@ def main(): run_state = RunState(spec_filename=args.filename, replay_with=args.replay_with) try: + # Validate API key is present + if not args.api_key: + raise MissingAPIKey( + "API key is required. Please set the CODEPLAIN_API_KEY environment variable or provide it with the --api-key argument." + ) + render(args, run_state, codeplain_api, event_bus) except InvalidFridArgument as e: console.error(f"Error rendering plain code: {str(e)}.\n") @@ -237,6 +243,8 @@ def main(): console.error(f"Error rendering plain code: {str(e)}\n") console.debug(f"Render ID: {run_state.render_id}") dump_crash_logs(args) + except MissingAPIKey as e: + console.error(f"Missing API key: {str(e)}\n") except Exception as e: console.error(f"Error rendering plain code: {str(e)}\n") console.debug(f"Render ID: {run_state.render_id}") diff --git a/plain2code_arguments.py b/plain2code_arguments.py index 35c7db4..60e3c2d 100644 --- a/plain2code_arguments.py +++ b/plain2code_arguments.py @@ -5,10 +5,6 @@ from plain2code_read_config import get_args_from_config CODEPLAIN_API_KEY = os.getenv("CODEPLAIN_API_KEY") -if not CODEPLAIN_API_KEY: - CLAUDE_API_KEY = os.getenv("CLAUDE_API_KEY") - if not CLAUDE_API_KEY: - raise ValueError("CODEPLAIN_API_KEY or CLAUDE_API_KEY environment variable is not set") DEFAULT_BUILD_FOLDER = "plain_modules" diff --git a/plain2code_exceptions.py b/plain2code_exceptions.py index e48e34e..cafdbbb 100644 --- a/plain2code_exceptions.py +++ b/plain2code_exceptions.py @@ -43,3 +43,7 @@ class MultipleRendersFound(Exception): class UnexpectedState(Exception): pass + + +class MissingAPIKey(Exception): + pass