Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion plain2code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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}")
Expand Down
4 changes: 0 additions & 4 deletions plain2code_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions plain2code_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ class MultipleRendersFound(Exception):

class UnexpectedState(Exception):
pass


class MissingAPIKey(Exception):
pass