openhab-core icon indicating copy to clipboard operation
openhab-core copied to clipboard

say function should return status value

Open smarthome-w opened this issue 3 years ago • 2 comments

Currently say function is void and caller has no information about execution status.

say function relies on many external services: external authentication, tts generation, chromecast devices accessibility. If any of those components has problems no sound is produced.

I.e. in my case GoogleTTS does not produce appropriate file in first call (for unique sentence), however does it in second one. So I prepared function:

val saySomething = [ String ttsMessage |
    logInfo("lambda", ttsMessage)
    var boolean googleSuccess = false

    var i = 0
    while((i=i+1) <= 3 && !googleSuccess) {
      logInfo("Say info", "{} - familyroom - attempt {}", ttsMessage, i)
      try {
        say (ttsMessage, "googletts:enUSStandardA", "chromecast:chromecast:familyroom")
        logInfo("Say error", "{} - familyroom - attempt {} - after say", ttsMessage, i)
        googleSuccess = true
      } catch (Throwable e) {
        logError("Say error", "{} - familyroom - attempt {}", ttsMessage, i)
      }
    }
    "executed"
]

A lot of stack traces is produced in the say execution. But none: result or exception are accessible to detect error within say function to retry execution.

say should be defined similar to executeCommand() i.e. as:

public static String say(...)

or throw proper exception.

smarthome-w avatar Dec 29 '21 22:12 smarthome-w

May I ask you to amend one of those stack traces? We maybe can identify a good place to handle those exceptions and map it to a user-friendly result.

cweitkamp avatar Jan 01 '22 11:01 cweitkamp

There are two examples:

  1. Error in oauth token refresh
2021-12-31 15:12:08.019 [ERROR] [ce.googletts.internal.GoogleCloudAPI] - Could not write /openhab/userdata/cache/org.openhab.voice.googletts/plPLStandardA_f8d770a6900e7ef0fec1c9abae653710.mp3 to cache
java.io.IOException: Exception in oauth communication, grant type refresh_token
        at org.openhab.core.auth.oauth2client.internal.OAuthConnector.doRequest(OAuthConnector.java:333) ~[?:?]
        at org.openhab.core.auth.oauth2client.internal.OAuthConnector.grantTypeRefreshToken(OAuthConnector.java:187) ~[?:?]
        at org.openhab.core.auth.oauth2client.internal.OAuthClientServiceImpl.refreshToken(OAuthClientServiceImpl.java:302) ~[?:?]
        at org.openhab.core.auth.oauth2client.internal.OAuthClientServiceImpl.getAccessTokenResponse(OAuthClientServiceImpl.java:336) ~[?:?]
        at org.openhab.voice.googletts.internal.GoogleCloudAPI.getAuthorizationHeader(GoogleCloudAPI.java:213) ~[?:?]
        at org.openhab.voice.googletts.internal.GoogleCloudAPI.synthesizeSpeechByGoogle(GoogleCloudAPI.java:422) ~[?:?]
        at org.openhab.voice.googletts.internal.GoogleCloudAPI.synthesizeSpeech(GoogleCloudAPI.java:334) ~[?:?]
        at org.openhab.voice.googletts.internal.GoogleTTSService.synthesize(GoogleTTSService.java:331) ~[?:?]
        at org.openhab.core.voice.internal.VoiceManagerImpl.say(VoiceManagerImpl.java:223) ~[?:?]
        at org.openhab.core.model.script.actions.Voice.say(Voice.java:121) ~[?:?]
        at org.openhab.core.model.script.actions.Voice.say(Voice.java:101) ~[?:?]

...
Caused by: java.util.concurrent.ExecutionException: javax.net.ssl.SSLHandshakeException: Abruptly closed by peer
        at org.eclipse.jetty.client.util.FutureResponseListener.getResult(FutureResponseListener.java:118) ~[?:?]
        at org.eclipse.jetty.client.util.FutureResponseListener.get(FutureResponseListener.java:101) ~[?:?]
        at org.eclipse.jetty.client.HttpRequest.send(HttpRequest.java:730) ~[?:?]
        at org.openhab.core.auth.oauth2client.internal.OAuthConnector.lambda$0(OAuthConnector.java:307) ~[?:?]
        at java.security.AccessController.doPrivileged(Native Method) ~[?:?]
        at org.openhab.core.auth.oauth2client.internal.OAuthConnector.doRequest(OAuthConnector.java:305) ~[?:?]
        ... 83 more
Caused by: javax.net.ssl.SSLHandshakeException: Abruptly closed by peer
        at org.eclipse.jetty.io.ssl.SslConnection$DecryptedEndPoint.fill(SslConnection.java:769) ~[?:?]
        at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.process(HttpReceiverOverHTTP.java:164) ~[?:?]
        at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.receive(HttpReceiverOverHTTP.java:79) ~[?:?]
        at org.eclipse.jetty.client.http.HttpChannelOverHTTP.receive(HttpChannelOverHTTP.java:131) ~[?:?]
        at org.eclipse.jetty.client.http.HttpConnectionOverHTTP.onFillable(HttpConnectionOverHTTP.java:172) ~[?:?]
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) ~[?:?]
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) ~[?:?]
        at org.eclipse.jetty.io.ssl.SslConnection$DecryptedEndPoint.onFillable(SslConnection.java:555) ~[?:?]
        at org.eclipse.jetty.io.ssl.SslConnection.onFillable(SslConnection.java:410) ~[?:?]
        at org.eclipse.jetty.io.ssl.SslConnection$2.succeeded(SslConnection.java:164) ~[?:?]
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) ~[?:?]
        at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) ~[?:?]
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883) ~[?:?]
        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034) ~[?:?]
        ... 1 more
        Suppressed: javax.net.ssl.SSLException: closing inbound before receiving peer's close_notify
                at sun.security.ssl.Alert.createSSLException(Alert.java:133) ~[?:?]
                at sun.security.ssl.Alert.createSSLException(Alert.java:117) ~[?:?]
                at sun.security.ssl.TransportContext.fatal(TransportContext.java:336) ~[?:?]
                at sun.security.ssl.TransportContext.fatal(TransportContext.java:292) ~[?:?]
  1. Error in communication:
2022-01-01 12:07:36.406 [ERROR] [ce.googletts.internal.GoogleCloudAPI] - Could not write /openhab/userdata/cache/org.openhab.voice.googletts/plPLStandardA_2abe1032ec85388fdc79514f2bc8f36d.mp3 to cache
java.io.IOException: java.util.concurrent.ExecutionException: java.io.EOFException: HttpConnectionOverHTTP@8ac70d::DecryptedEndPoint@f39d1c{l=/172.17.0.3:45684,r=texttospeech.googleapis.com/172.217.16.42:443,OPEN,fill=-,flush=-,to=46115186/0}
        at org.openhab.core.io.net.http.HttpUtil.executeUrlAndGetReponse(HttpUtil.java:260) ~[?:?]
        at org.openhab.core.io.net.http.HttpUtil.executeUrl(HttpUtil.java:155) ~[?:?]
        at org.openhab.core.io.net.http.HttpUtil.executeUrl(HttpUtil.java:130) ~[?:?]
        at org.openhab.core.io.net.http.HttpRequestBuilder.getContentAsString(HttpRequestBuilder.java:135) ~[?:?]
        at org.openhab.voice.googletts.internal.GoogleCloudAPI.synthesizeSpeechByGoogle(GoogleCloudAPI.java:425) ~[?:?]
        at org.openhab.voice.googletts.internal.GoogleCloudAPI.synthesizeSpeech(GoogleCloudAPI.java:334) ~[?:?]
        at org.openhab.voice.googletts.internal.GoogleTTSService.synthesize(GoogleTTSService.java:331) ~[?:?]
        at org.openhab.core.voice.internal.VoiceManagerImpl.say(VoiceManagerImpl.java:223) ~[?:?]
        at org.openhab.core.model.script.actions.Voice.say(Voice.java:121) ~[?:?]
        at org.openhab.core.model.script.actions.Voice.say(Voice.java:101) ~[?:?]

...

Caused by: java.util.concurrent.ExecutionException: java.io.EOFException: HttpConnectionOverHTTP@8ac70d::DecryptedEndPoint@f39d1c{l=/172.17.0.3:45684,r=texttospeech.googleapis.com/172.217.16.42:443,OPEN,fill=-,flush=-,to=46115186/0}
        at org.eclipse.jetty.client.util.FutureResponseListener.getResult(FutureResponseListener.java:118) ~[?:?]
        at org.eclipse.jetty.client.util.FutureResponseListener.get(FutureResponseListener.java:101) ~[?:?]
        at org.eclipse.jetty.client.HttpRequest.send(HttpRequest.java:730) ~[?:?]
        at org.openhab.core.io.net.http.HttpUtil.executeUrlAndGetReponse(HttpUtil.java:251) ~[?:?]
        ... 74 more
Caused by: java.io.EOFException: HttpConnectionOverHTTP@8ac70d::DecryptedEndPoint@f39d1c{l=/172.17.0.3:45684,r=texttospeech.googleapis.com/172.217.16.42:443,OPEN,fill=-,flush=-,to=46115186/0}
        at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.earlyEOF(HttpReceiverOverHTTP.java:376) ~[?:?]
        at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:1614) ~[?:?]
        at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.shutdown(HttpReceiverOverHTTP.java:259) ~[?:?]
        at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.process(HttpReceiverOverHTTP.java:181) ~[?:?]
        at org.eclipse.jetty.client.http.HttpReceiverOverHTTP.receive(HttpReceiverOverHTTP.java:79) ~[?:?]
        at org.eclipse.jetty.client.http.HttpChannelOverHTTP.receive(HttpChannelOverHTTP.java:131) ~[?:?]
        at org.eclipse.jetty.client.http.HttpConnectionOverHTTP.onFillable(HttpConnectionOverHTTP.java:172) ~[?:?]
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) ~[?:?]
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) ~[?:?]
        at org.eclipse.jetty.io.ssl.SslConnection$DecryptedEndPoint.onFillable(SslConnection.java:555) ~[?:?]
        at org.eclipse.jetty.io.ssl.SslConnection.onFillable(SslConnection.java:410) ~[?:?]
        at org.eclipse.jetty.io.ssl.SslConnection$2.succeeded(SslConnection.java:164) ~[?:?]
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) ~[?:?]
        at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) ~[?:?]
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883) ~[?:?]
        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034) ~[?:?]
        ... 1 more
2022-01-01 12:07:36.629 [WARN ] [core.voice.internal.VoiceManagerImpl] - Error saying 'Some message.': Could not read from Google Cloud TTS Service
org.openhab.core.voice.TTSException: Could not read from Google Cloud TTS Service
        at org.openhab.voice.googletts.internal.GoogleTTSService.synthesize(GoogleTTSService.java:333) ~[?:?]
        at org.openhab.core.voice.internal.VoiceManagerImpl.say(VoiceManagerImpl.java:223) ~[?:?]
        at org.openhab.core.model.script.actions.Voice.say(Voice.java:121) ~[?:?]
        at org.openhab.core.model.script.actions.Voice.say(Voice.java:101) ~[?:?]

To be more specific. This is installation in docker with set callbackUrl property.

If you want I can prepare more detailed logs with TRACE mode.

These specific problems should be rather addressed in openhab-addons repo. But in general it would be great to have overall possibility to catch unnormal behavior.

I understand that it is not simple:

  • if you just throw an exception (through stack calls to the highest script level) it can be desctructive for all OH users and their rules logic
  • if you decide to change void to int or String it will require to change all TTS addons to apply API modification.

smarthome-w avatar Jan 01 '22 12:01 smarthome-w