Skip to content

fix: raise ValueError instead of exit(1) on missing API key; return error string from searxSearch on network failure#470

Open
octo-patch wants to merge 1 commit intoFosowl:mainfrom
octo-patch:fix/get-api-key-exit1-and-searxng-error-return
Open

fix: raise ValueError instead of exit(1) on missing API key; return error string from searxSearch on network failure#470
octo-patch wants to merge 1 commit intoFosowl:mainfrom
octo-patch:fix/get-api-key-exit1-and-searxng-error-return

Conversation

@octo-patch
Copy link
Copy Markdown
Contributor

Problem

Two related error-handling bugs crash the backend or break the tool contract:

  1. Provider.get_api_key() calls exit(1) when the API key is missing (sources/llm_provider.py:63). This terminates the entire backend process immediately — including when running inside Docker — instead of surfacing a clear error. Users then see the WebUI as offline with no useful diagnostics.

  2. searxSearch.execute() raises an Exception on RequestException (sources/tools/searxSearch.py:107). All other execute() implementations return an error string; raising here breaks the tool API contract assumed by execute_modules() in agent.py, crashes the agent mid-task, and also causes test_execute_request_exception to fail (the test correctly expects a return value).

Solution

  • Replace exit(1) in get_api_key() with raise ValueError(...) so callers receive a proper Python exception with a descriptive message rather than a silent process crash.
  • Replace the raise Exception(...) in searxSearch.execute() with a return of an error string (prefixed with "Error during search:" so execution_failure_check() detects it correctly).

Testing

  • python -m pytest tests/test_searx_search.py — all 9 tests pass, including test_execute_request_exception which now correctly receives an error string instead of an unhandled exception.
  • python -m pytest tests/ — only the pre-existing test_save_and_load_memory failure remains (caused by a termcolor<2.4.0 installation in the test environment, unrelated to this PR).

…rror string from searxSearch on network failure

- In Provider.get_api_key(), replace exit(1) with ValueError so the
  backend can handle a missing API key gracefully instead of crashing
  the entire process.
- In searxSearch.execute(), return an error string on RequestException
  instead of raising, consistent with the tool API contract (execute()
  should always return str). This also fixes the test_execute_request_exception
  test which expected a return value, not a raised exception.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant