elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.48k stars 659 forks source link

Better error message for error: What node should I take over? #2263

Open aminnairi opened 2 years ago

aminnairi commented 2 years ago

Quick Summary:

The error message related to the case where one mistakenly provide a node property that is equal (or evaluated to) null to the init method when creating an Elm application is somewhat misleading because even though the node property is provided (and it does not point to any valid DOM element) it tells the user that it should use the node property, which is already the case and the error message does not really help pinpoint exactly where the error is.

SSCCE

<html>
<head>
  <style>
    /* you can style your program here */
  </style>
</head>
<body>
  <!-- The Elm node below -->
  <article></article>
  <script>
    var app = Elm.Main.init({ node: document.querySelector('main') })
    // The node "main" does not exist and this call is equal to null
  </script>
</body>
</html>

Additional Details

I didn't dive in the source-code, but I guess there should be two (or more) error messages here.

Elm.Main.init();
// First error when the first argument is missing
Elm.Main.init([]);
// Second error when the first argument is not an object
Elm.Main.init({});
// Third error when the object is provided but the node property is missing (when using Browser.* that expect a node...)
Elm.Main.init({node: null});
// Fourth error when the object is provided and the node property is provided but the node is not equal to an instanceof Element
Elm.Main.init({node: document.getElementById("elm"), happy: false});
// Fifth error when there are properties that are not expected

Of course replacing those error message with all the great error messages design that makes Elm a delight to use!

github-actions[bot] commented 2 years ago

Thanks for reporting this! To set expectations:

Finally, please be patient with the core team. They are trying their best with limited resources.