Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove error message on null template #2735

Merged

Conversation

jpelgrom
Copy link
Member

Summary

In #2653 it was discovered that templates can be valid and return null, and some simple changes were made to handle it.

This PR builds on it and addresses a comment by another user:

The app presents null as "Error in template".

IMO, that message is not correct given the template is syntactically valid and doesn't throw an exception: null is a perfectly valid, if not intended, result here. If I didn't know this now, I'd have been going over the template for syntax errors and ripping my hair out wondering why I couldn't find any; null would tell me that it's working, just not giving me the info I want. That said, this could've already been hashed out elsewhere and decided on already so I end my comments on it here.

null will now be shown as "null" like in the frontend, and "Error in template" will only be shown if there is actually an error. If users want to avoid seeing "null" it can be handled in the template.

Screenshots

n/a, template widget/tile hasn't visually changed

Link to pull request in Documentation repository

n/a

Any other notes

On error the server will give the app a response like this:

{"template": {"error": "TemplateSyntaxError: expected name or number"}}

Which throws:

A stacktrace
2022-07-30 21:28:26.642 32676-32715/io.homeassistant.companion.android.debug E/TemplateWidgetConfigAct: Exception while rendering template
    io.homeassistant.companion.android.common.data.integration.IntegrationException: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`)
        at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 1, column: 14] (through reference chain: java.util.LinkedHashMap["template"])
        at io.homeassistant.companion.android.common.data.integration.impl.IntegrationRepositoryImpl.renderTemplate(IntegrationRepositoryImpl.kt:177)
        at io.homeassistant.companion.android.common.data.integration.impl.IntegrationRepositoryImpl$renderTemplate$1.invokeSuspend(Unknown Source:15)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
        at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
        at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
     Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`)
        at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 1, column: 14] (through reference chain: java.util.LinkedHashMap["template"])
        at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1741)
        at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1515)
        at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1420)
        at com.fasterxml.jackson.databind.DeserializationContext.extractScalarFromObject(DeserializationContext.java:932)
        at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:62)
        at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:11)
        at com.fasterxml.jackson.databind.deser.std.MapDeserializer._readAndBindStringKeyMap(MapDeserializer.java:609)
        at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:437)
        at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:32)
        at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:323)
        at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:2051)
        at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1459)
        at retrofit2.converter.jackson.JacksonResponseBodyConverter.convert(JacksonResponseBodyConverter.java:33)
        at retrofit2.converter.jackson.JacksonResponseBodyConverter.convert(JacksonResponseBodyConverter.java:23)
        at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:243)
        at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:153)
        at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)
        at java.lang.Thread.run(Thread.java:1012)

 - Null is a valid value for a template so the app should reflect that instead of suggesting there is an error, which may cause users to start looking in the wrong place.
Copy link
Member

@dshokouhi dshokouhi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@JBassett JBassett merged commit 9fc98e4 into home-assistant:master Aug 3, 2022
@jpelgrom jpelgrom deleted the improve-template-null-preview branch August 4, 2022 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants