-
Notifications
You must be signed in to change notification settings - Fork 99
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
Runtime exception: passing "" to Html.node #47
Comments
Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it! Here is what to expect next, and if anyone wants to comment, keep these things in mind. |
What should happen instead? Is it worth it to add a check on every |
Definitely not, but I could see making the dangerous one internal-use only, and having a public-facing That way end users could do this: sidebar : List Attribute a -> List Html a -> Html a
sidebar =
case Html.customNode "sidebar" of
Ok fn ->
fn
Err err ->
Debug.crash "Invalid node" In this world there's an inconsequential bit of page load overhead, but explosions are gonna happen on startup (like they do with This is more work for people who want to make custom nodes, but to be fair, it is for sure an advanced feature. |
How do you know if a node is good on startup? Would we need to maintain a list of all valid tags? If so, the maintenance burden of that seems worse than the original problem. |
Hm, good point...it's easy enough to check for Maybe the best resolution here is to add a big warning saying "if you pass an invalid string here, this can crash" or something to that effect? |
According with DOM Spec the From HTML Syntax spec, we can see that valid names are only But I also checked that createElement raises the exception with tagNames starting with So, checking the conditions above should be enough to use signature suggested by @rtfeldman |
Yeah I wouldn't trust that there aren't more cases like that lurking out there, especially given that you immediately found one that wasn't in the spec. Also, cross-browser. 😞 |
Yeah, it is possible to have more cases out there, but I think your suggestion is the "best effort" to avoid RunTimeException, and the checks above could be the starting point to use it. If we found other possible, non-documented, runtime exception from I just think that, as you said, |
Why do all this work when the suggestion is to have it
In both cases bad things crash. In one case everyone does less work and the results are ultimately the same. I'll add that the only reason we even know about this is because of #46. As far as we know, this case has never come up in practice. It certainly has not been reported. So this either (1) never happens or (2) when it does happen, no one is upset about it. That is not the kind of motivation we usually have for breaking changes. |
Yeah, that all makes sense to me. I feel like it could be worth adding a warning to the docs to the effect of "Be careful! This can throw a runtime exception if you give it an invalid node name" but that's about it. |
I had to agree with you @evancz, and you bring a very important point: the change will be a breaking change. |
To reproduce, do this in Try Elm:
Result is the runtime exception:
Related: https://github.com/elm-lang/html/issues/46 - same behavior for passing
""
toAttribute
.The text was updated successfully, but these errors were encountered: