Skip to content
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

elm-test --watch crashes if Elm code doesn't compile #399

Closed
MartinSStewart opened this issue Nov 19, 2019 · 1 comment · Fixed by #453
Closed

elm-test --watch crashes if Elm code doesn't compile #399

MartinSStewart opened this issue Nov 19, 2019 · 1 comment · Fixed by #453

Comments

@MartinSStewart
Copy link

MartinSStewart commented Nov 19, 2019

Steps to reproduce:

  1. Download sscce.zip and install NPM packages
  2. Run yarn test in terminal
  3. Notice that elm-test will start and then immediately crash with the following exception
(node:3644) UnhandledPromiseRejectionWarning: Compilation failed while attempting to run `elm make` on /Users/martinstewart/Desktop/sscce
(node:3644) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3644) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Node version: v10.16.0
OS: MacOS
Elm version: 0.19.1

@lydell
Copy link
Collaborator

lydell commented Oct 10, 2020

Update! It used to crash like this:

-- CYCLIC DEFINITION ------------------------------------------ src/MyModule.elm

The `a` value is defined directly in terms of itself, causing an infinite loop.

4| a = a
   ^
Are you are trying to mutate a variable? Elm does not have mutation, so when I
see a defined in terms of a, I treat it as a recursive definition. Try giving
the new value a new name!

Maybe you DO want a recursive value? To define a we need to know what a is, so
let’s expand it. Wait, but now we need to know what a is, so let’s expand it...
This will keep going infinitely!

Hint: The root problem is often a typo in some variable name, but I recommend
reading <https://elm-lang.org/0.19.1/bad-recursion> for more detailed advice,
especially if you actually do need a recursive value.

(node:93627) UnhandledPromiseRejectionWarning: Compilation failed while attempting to run `elm make` on /Users/lydell/Downloads/sscce
(Use `node --trace-warnings ...` to show where the warning was created)
(node:93627) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:93627) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Since #448 it exits like this:

-- CYCLIC DEFINITION ------------------------------------------ src/MyModule.elm

The `a` value is defined directly in terms of itself, causing an infinite loop.

4| a = a
   ^
Are you are trying to mutate a variable? Elm does not have mutation, so when I
see a defined in terms of a, I treat it as a recursive definition. Try giving
the new value a new name!

Maybe you DO want a recursive value? To define a we need to know what a is, so
let’s expand it. Wait, but now we need to know what a is, so let’s expand it...
This will keep going infinitely!

Hint: The root problem is often a typo in some variable name, but I recommend
reading <https://elm-lang.org/0.19.1/bad-recursion> for more detailed advice,
especially if you actually do need a recursive value.

undefined

So:

  • No more unhandled promise rejection warnings.
  • There’s a weird undefined at the end.
  • It feels like the watcher should still keep going and automatically try to run the tests again when the user has fixed their code.

harrysarson pushed a commit that referenced this issue Oct 16, 2020
Fixes #399.

Previously, if there was an error in src/ for a package project, elm-test --watch would immediately exit. This was because we compile src/ first to get .elmi files for the files in there so that elmi-to-json can find the exact dependencies there. But since #451 we don’t use elmi-to-json to find exact dependencies anymore – we use elm-json instead – so there’s no need for that compilation step anymore. I removed that, which fixes the issue and also improves test run time since the compiler is invoked one time less.

As for the undefined log issue, that was because of promises being rejected with strings while the .catch code expected Error objects. "some string".message is undefined, so that’s where it came from. I updated to reject with Error objects instead.

This allowed for some pretty nice cleanups.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants