fix: exit the goose and show the error message when provider environment variable is not set#103
Conversation
| break | ||
| except Exception: | ||
| pass | ||
| else: |
There was a problem hiding this comment.
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.
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
else:
provider = RECOMMENDED_DEFAULT
so that we don't set it to something niche?
tests/cli/test_session.py
Outdated
| 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( |
There was a problem hiding this comment.
:nit: we can make this easier to read by forcing ruff format to newline with trailing command and parenthesis
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,
):There was a problem hiding this comment.
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.
There was a problem hiding this comment.
oh, sorry I missed the extra brackets. I've updated and it works now!
…ey-not-specified * main: chore: setup workspace for exchange (#105)
…ovider/moderator is unknown
baxen
left a comment
There was a problem hiding this comment.
This is great! Much clearer
| from typing import List | ||
|
|
||
|
|
||
| class LoadExchangeAttributeError(Exception): |
| return cls(client) | ||
|
|
||
| @classmethod | ||
| def _get_env_variable(cls: Type["AzureProvider"], key: str) -> str: |
There was a problem hiding this comment.
nit: i'd just call the helper directly instead of adding the new method?
| return tool_config | ||
|
|
||
| @classmethod | ||
| def _get_env_variable(cls: Type["BedrockProvider"], key: str) -> str: |
| break | ||
| except Exception: | ||
| pass | ||
| else: |
There was a problem hiding this comment.
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
else:
provider = RECOMMENDED_DEFAULT
so that we don't set it to something niche?
* main: fix: exit the goose and show the error message when provider environment variable is not set (#103) fix: Update OpenAI pricing per https://openai.com/api/pricing/ (#110) fix: update developer tool prompts to use plan task status to match allowable statuses update_plan tool call (#107) fix: removed the panel in the output so that the user won't have unnecessary pane borders in the copied content (#109) docs: update links to exchange to the new location (#108) chore: setup workspace for exchange (#105)
…ent variable is not set (#103)
* main: (41 commits) chore: Add goose providers list command (#116) docs: working ollama for desktop (#125) docs: format and clean up warnings/errors (#120) docs: update deploy workflow (#124) feat: Implement a goose run command (#121) feat: saved api_key to keychain for user (#104) docs: add callout plugin (#119) chore: add a page to docs for Goose application examples (#117) fix: exit the goose and show the error message when provider environment variable is not set (#103) fix: Update OpenAI pricing per https://openai.com/api/pricing/ (#110) fix: update developer tool prompts to use plan task status to match allowable statuses update_plan tool call (#107) fix: removed the panel in the output so that the user won't have unnecessary pane borders in the copied content (#109) docs: update links to exchange to the new location (#108) chore: setup workspace for exchange (#105) fix: resolve uvx when using a git client or IDE (#98) ci: add include-markdown for mkdocs (#100) chore: fix broken badge on readme (#102) feat: add global optional user goosehints file (#73) docs: update docs (#99) chore(release): release 0.9.3 (#97) ...
…ent variable is not set (#103)
…ent variable is not set (block#103)

Why
Currently it throws a runtime error and print the stack trace when
This make it hard for users to understand what is going.
What
Exchange
provider,env_variable. When providers fetch the environment variable for api key, it will raise this error if the environment variable is not availableWith the above custom erross we can construct user friendly messages in goose
goose
screenshots

Please give feedback including the content and presentation of these error message. Thank you!