Open MichaelBrunn3r opened 2 weeks ago
Instead of fixing the issue with instanceof
, I came up with an alternative solution.
if (!(err instanceof StructError)) {
return { warnings: [err.message], errors: undefined };
}
The reason only one error from a superstruct error is displayed, is because we return an array with one element warnings: [err.message]
.
Instead we could check if the error has multiple messages:
if (!(err instanceof StructError)) {
if(Array.isArray(err["messages"])) {
return { warnings: err["messages"], errors: undefined };
}
return { warnings: [err.message], errors: undefined };
}
This way, custom cards creators could add a "messages" field to their errors, if they want to display multiple failures.
Checklist
Describe the issue you are experiencing
(I assume "Please do not report issues for custom cards" refers to issues regarding something like "Mushroom Cards". I hope this is the right place to report this)
Custom editor cards cannot display more than one error.
HuiElementEditor._updateConfigElement
callssetConfig
on custom editor cards. If an error is thrown, it is passed tohandleStructError
. The function uses this code to handle errors that are notStructError
s (from superstruct):Unfortunatelly, even when using superstruct for my own custom cards, the code thinks they are not
StructError
s. My undertanding is, thatinstanceof
checks iferr.__proto__
andStructError
are the same object. Since HomeAssistant and I both use our own instance of superstruct, ourStructError
classes are different objects.Describe the behavior you expected
If a custom editors
setConfig
function returns a superstruct error, it should be displayed the same way HomeAssistant displays internal superstruct errorsSteps to reproduce the issue
Set the config to an invalid value:
What version of Home Assistant Core has the issue?
core-2024.6.2
What was the last working version of Home Assistant Core?
No response
In which browser are you experiencing the issue with?
No response
Which operating system are you using to run this browser?
No response
State of relevant entities
No response
Problem-relevant frontend configuration
No response
Javascript errors shown in your browser console/inspector
No response
Additional information
Superstruct error is treated like any other error:![image](https://github.com/home-assistant/frontend/assets/19626539/713180b7-186b-4d9f-8fc2-d8ae26cfb854)
With some hacks the same error is displayed the same way HomeAssistant does it. It's even translated![image](https://github.com/home-assistant/frontend/assets/19626539/74072aee-41c4-4e05-a2a8-67365f4f733e)