From c03e0ab185de658ad1f8b599eac0e56504bd9443 Mon Sep 17 00:00:00 2001 From: Tjaz Erzen Date: Mon, 26 Jan 2026 12:05:26 +0100 Subject: [PATCH 1/2] Handle error for missing api key better --- plain2code.py | 10 +++++++++- plain2code_arguments.py | 4 ---- plain2code_exceptions.py | 4 ++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/plain2code.py b/plain2code.py index b4e2cd7..91bf226 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 --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 From 861b8349c4c393eea69c4e0950ce7019129dcfa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tja=C5=BE=20Er=C5=BEen?= Date: Mon, 26 Jan 2026 14:14:28 +0100 Subject: [PATCH 2/2] Update plain2code.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improve error message for missing API key (kit) Co-authored-by: Žan Jonke --- plain2code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plain2code.py b/plain2code.py index 91bf226..904d496 100644 --- a/plain2code.py +++ b/plain2code.py @@ -211,7 +211,7 @@ def main(): # 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 --api-key argument." + "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)