Skip to content

Commit abeb01e

Browse files
better error handling and read api key from rc only
1 parent a0ff82f commit abeb01e

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

codeflash/api/cfapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def get_user_id() -> Optional[str]:
101101
console.print(f"[bold red]{msg}[/bold red]")
102102
if console.quiet: # lsp
103103
logger.debug(msg)
104-
return None
104+
return f"Error: {msg}"
105105
sys.exit(1)
106106
return userid
107107

codeflash/code_utils/env_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def check_formatter_installed(formatter_cmds: list[str], exit_on_failure: bool =
3636
def get_codeflash_api_key() -> str:
3737
if console.quiet: # lsp
3838
# prefer shell config over env var in lsp mode
39-
api_key = read_api_key_from_shell_config() or os.environ.get("CODEFLASH_API_KEY")
39+
api_key = read_api_key_from_shell_config()
4040
else:
4141
api_key = os.environ.get("CODEFLASH_API_KEY") or read_api_key_from_shell_config()
4242

codeflash/lsp/beta.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ def _initialize_optimizer_if_valid(server: CodeflashLanguageServer) -> dict[str,
130130
if user_id is None:
131131
return {"status": "error", "message": "api key not found or invalid"}
132132

133+
if user_id.startswith("Error: "):
134+
error_msg = user_id[7:]
135+
return {"status": "error", "message": error_msg}
136+
133137
from codeflash.optimization.optimizer import Optimizer
134138

135139
server.optimizer = Optimizer(server.args)

0 commit comments

Comments
 (0)