Skip to content

fix: wrap Google Cloud client initialization errors in RequestError - #922

Open
AyhamJo7 wants to merge 1 commit into
Uberi:masterfrom
AyhamJo7:fix/361-google-cloud-error-handling
Open

AyhamJo7 wants to merge 1 commit into
Uberi:masterfrom
AyhamJo7:fix/361-google-cloud-error-handling

Conversation

@AyhamJo7

Copy link
Copy Markdown

Closes #361

Summary

  • recognize_google_cloud documents that it raises speech_recognition.RequestError if the speech recognition operation fails, if credentials are invalid, or if there is no Internet connection.
  • While client.recognize(...) catches GoogleAPICallError and URLError, speech.SpeechClient() / speech.SpeechClient.from_service_account_json(...) initialization was outside the try block, allowing google.auth.exceptions.GoogleAuthError (e.g., DefaultCredentialsError), OSError, or ValueError from malformed credentials to escape as raw exceptions instead of RequestError.
  • Wrap SpeechClient initialization in try ... except (GoogleAuthError, OSError, ValueError) as e: raise RequestError(e) and add unit tests covering GoogleAPICallError, GoogleAuthError, and UnknownValueError in tests/recognizers/test_google_cloud.py.

This branch has not been deployed

No deployments
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.

Google Cloud backend errors are not properly caught

1 participant