Open lz100 opened 3 years ago
Yeah, way too much error checking appears to happen at print time, not at construction time. This makes errors hard to track down.
Here's a small reprex:
x <- htmltools::p(mean)
x
#> Error in as.character(x): cannot coerce type 'closure' to vector of type 'character'
x <- htmltools::p(classes = letters, "x")
x
#> Error in if (!is.na(attribValue)) {: the condition has length > 1
Created on 2021-08-11 by the reprex package (v2.0.0)
If I do
htmltools::tags$p(list(1:2))
I understand, because I have a list, but the error is coming from this
writeImpl
function, not thetags$p
function. Imagine we are writing deep levels of UI, giving this error is very hard to debug. I have no idea where it comes from.It doesn't give you the error right away, let's say we are writing a Shiny app
This actually works when you assign it. It error only happens when the UI gets evaluated somehow later. This creates the false impression that my UI has no problem, but it has problems.
If I use
htmltools::tags$p(list(1))
, this will work with no problem, but it is not a character and the item inside the list is not character either, so the error message is misleading. People will ask why do my list and non-character value work here?Hope we can have some better error messages and better assertions before value assignment.