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
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two related error-handling bugs crash the backend or break the tool contract:
Provider.get_api_key()callsexit(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.searxSearch.execute()raises anExceptiononRequestException(sources/tools/searxSearch.py:107). All otherexecute()implementations return an error string; raising here breaks the tool API contract assumed byexecute_modules()inagent.py, crashes the agent mid-task, and also causestest_execute_request_exceptionto fail (the test correctly expects a return value).Solution
exit(1)inget_api_key()withraise ValueError(...)so callers receive a proper Python exception with a descriptive message rather than a silent process crash.raise Exception(...)insearxSearch.execute()with areturnof an error string (prefixed with"Error during search:"soexecution_failure_check()detects it correctly).Testing
python -m pytest tests/test_searx_search.py— all 9 tests pass, includingtest_execute_request_exceptionwhich now correctly receives an error string instead of an unhandled exception.python -m pytest tests/— only the pre-existingtest_save_and_load_memoryfailure remains (caused by atermcolor<2.4.0installation in the test environment, unrelated to this PR).