-
Notifications
You must be signed in to change notification settings - Fork 5.6k
fix: exit the goose and show the error message when provider environment variable is not set #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c321c8c
6cb7cfc
dfb4522
a710080
b52f3a3
40fab9b
1b725f7
451cda4
7829262
03af0c6
4e97f0a
36b5d2c
208b265
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| import pytest | ||
| from exchange import Exchange, Message, ToolUse, ToolResult | ||
| from exchange.providers.base import MissingProviderEnvVariableError | ||
| from goose.cli.prompt.goose_prompt_session import GoosePromptSession | ||
| from goose.cli.prompt.user_input import PromptAction, UserInput | ||
| from goose.cli.session import Session | ||
|
|
@@ -151,3 +152,17 @@ def test_set_generated_session_name(create_session_with_mock_configs, mock_sessi | |
| with patch("goose.cli.session.droid", return_value=generated_session_name): | ||
| session = create_session_with_mock_configs({"name": None}) | ||
| assert session.name == generated_session_name | ||
|
|
||
|
|
||
| def test_create_exchange_exit_when_env_var_does_not_exist(create_session_with_mock_configs, mock_sessions_path): | ||
| session = create_session_with_mock_configs() | ||
| expected_error = MissingProviderEnvVariableError(env_variable="OPENAI_API_KEY", provider="openai") | ||
| with patch("goose.cli.session.build_exchange", side_effect=expected_error), patch( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :nit: we can make this easier to read by forcing with (
patch("goose.cli.session.build_exchange", side_effect=expected_error),
patch("goose.cli.session.print") as mock_print,
patch("sys.exit") as mock_exit,
):
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I prefer the separated lines too. However, I had a look, it seems that ruff format is unable to do it as it only supports some light formatting rules.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, sorry I missed the extra brackets. I've updated and it works now! |
||
| "goose.cli.session.print" | ||
| ) as mock_print, patch("sys.exit") as mock_exit: | ||
| session._create_exchange() | ||
| mock_print.call_args_list[0][0][0].renderable == ( | ||
| "Missing environment variable OPENAI_API_KEY for provider openai. ", | ||
| "Please set the required environment variable to continue.", | ||
| ) | ||
| mock_exit.assert_called_once_with(1) | ||

Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need this message. The error message (env var is not set) will be thrown when the provider is loaded while creating the session.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so in this case, the provider value that is returned below will be whatever is last in the list of providers, and then be used to set the default profile. It will later error like you say.
Should we do
so that we don't set it to something niche?