jfmengels / node-elm-review

CLI for elm-review
https://package.elm-lang.org/packages/jfmengels/elm-review/latest/
BSD 3-Clause "New" or "Revised" License
48 stars 25 forks source link

Improve error message when using --template with a package elm.json #148

Open jfmengels opened 5 months ago

jfmengels commented 5 months ago

When running elm-review --template jfmengels/elm-review-unused, we get the following error:

-- UNEXPECTED ERROR ------------------------------------------------------------

I ran into an unexpected error. Please open an issue at the following link:
  https://github.com/jfmengels/node-elm-review/issues/new

Please include this error message and as much detail as you can provide. If you
can, please provide a setup that makes it easy to reproduce the error. That will
make it much easier to fix the issue.

Below is the error that was encountered.
--------------------------------------------------------------------------------
TypeError: Cannot convert undefined or null to object
    at Function.entries (<anonymous>)
    at Object.update (/Users/jeroen/dev/node-elm-review/lib/template-dependencies.js:270:10)
    at Object.getRemoteElmJson (/Users/jeroen/dev/node-elm-review/lib/remote-template.js:101:31)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async buildFromGitHubTemplate (/Users/jeroen/dev/node-elm-review/lib/build.js:208:25)
    at async runElmReview (/Users/jeroen/dev/node-elm-review/lib/main.js:64:51)

The issue is that the elm.json at the given path is for an Elm package, not for an Elm application as is expected. the issue here is that the target should have been jfmengels/elm-review-unused/example (for instance) and not the root jfmengels/elm-review-unused.

An improvement here would be to check the type of the elm.json. If it's an application, then we should continue as expected. If it's a package, then we should report a more helpful error (potentially asking to check whether there is a example or preview folder in that repository).