kaocha icon indicating copy to clipboard operation
kaocha copied to clipboard

Error on Windows as of 1.62.993

Open skynet-gh opened this issue 3 years ago • 9 comments

I'm getting this error now when running kaocha on my project:

> clj -M:kaocha
java.nio.file.NotDirectoryException: tests.edn
 at sun.nio.fs.WindowsWatchService$Poller.implRegister (WindowsWatchService.java:379)
    sun.nio.fs.AbstractPoller.processRequests (AbstractPoller.java:266)
    sun.nio.fs.WindowsWatchService$Poller.run (WindowsWatchService.java:596)
    java.lang.Thread.run (Thread.java:833)
[watch] watching stopped.

deps.edn alias and tests.edn

Looks like the file watcher changes are causing it to think tests.edn should be a directory for some reason. Adding :kaocha.watch/type :hawk does not fix it.

skynet-gh avatar Feb 16 '22 15:02 skynet-gh

:kaocha.watch/type :hawk does not fix it

Hmmmm! This is weird. Because using that flag it should have reverted back to the old watching mechanism. Maybe there has been an unintended change in this release? 🤔

Thanks for reporting this issue I personally don't use windows so it might be hard to debug this! Any help would be appreciated.

At the risk of asking the obvious, does the immediate last release of Kaocha work fine for you?

oxalorg avatar Feb 16 '22 15:02 oxalorg

:kaocha.watch/type :hawk does not fix it

Hmmmm! This is weird. Because using that flag it should have reverted back to the old watching mechanism. Maybe there has been an unintended change in this release? 🤔

Actually, I was wrong, I was putting :kaocha.watch/type :hawk in the test config and not top-level. Putting it top-level works!

At the risk of asking the obvious, does the immediate last release of Kaocha work fine for you?

It does not but I'll use the workaround of hawk for now, thanks!

skynet-gh avatar Feb 16 '22 15:02 skynet-gh

Looking at the Beholder repository, it looks like Beholder supports Windows, so I'm not sure why this failed. Based on the error, it could be a bug in the WindowsWatchService. In that case, it may be a version-specific issue.

alysbrooks avatar Sep 16 '22 23:09 alysbrooks

So Beholder doesn't support file-level watching, which we try to do for tests.edn. Apparently the WindowWatchService notices, and the ones for Linux and macOS don't (and instead silently fail). There's a couple options:

  • Watch the whole project directory and filter out events we don't want. The main issue here is that if you're doing ClojureScript builds or other operations that touch a lot of files, there's a lot of events to filter out.
  • Poll. I normally wouldn't consider this, but we would be polling a very small number of files, so it might be okay.
  • Add some sort of file-level watching upstream. Apparently, the operating system-level file watch functionality is directory-based, so this might be an uphill battle on the JDK or io.methvin.watcher level. I could see NextJournal going for it, so I might reach out to them. The code would be fairly similar whether it goes in Kaocha or Beholder so any design or coding wouldn't be wasted either.

alysbrooks avatar Sep 19 '22 22:09 alysbrooks

Looking at the code I think we should revisit this implementation, it starts two watchers, one is given all the test-paths/source-paths, the other is given #{config-file}, i.e. tests.edn. I think instead we can use a single watcher at the project top-level, and then filter for the stuff we care about.

Slightly different use case but there's some code here that can server as inspiration. It takes a set of directories, and reduces it to the minimum set by removing directories that are children of other directories already included in the set. https://github.com/lambdaisland/launchpad/blob/main/src/lambdaisland/launchpad/watcher.clj

So here it'll be similar

  • start from (concat test-paths source-paths [project-root])
  • remove any redundant paths (most of the time all that will be left is [project-root], but there could be test/source paths outside of the project root
  • watch those paths
  • filter events by checking again against the initial list ((concat test-paths source-paths [project-root])) (see Path#startsWith

plexus avatar Sep 20 '22 08:09 plexus

So Beholder doesn't support file-level watching, which we try to do for tests.edn. Apparently the WindowWatchService notices, and the ones for Linux and macOS don't (and instead silently fail).

Since it sounds like watching the config file doesn't currently work on any platform, would it be possible to get an interim band-aid of just removing this block? This would get rid of the exception on Windows, and Linux and Mac wouldn't suffer for it because their watchers are failing silently anyway.

colin-p-hill avatar Jan 06 '23 21:01 colin-p-hill

@colin-p-hill That's not a bad idea. I think we'd probably make it Hawk-only instead of removing it, though.

alysbrooks avatar Jan 06 '23 22:01 alysbrooks

@skynet-gh @colin-p-hill I just merged a temporary fix to this issue similar to what Colin suggested. You can point Kaocha to the latest changeset 7d6c897bfd85fd66aea0c45fcbb62de37733f374 or wait until we publish a new release.

{lambdaisland/kaocha {:git/url "https://github.com/lambdaisland/kaocha"
                      :git/sha "7d6c897bfd85fd66aea0c45fcbb62de37733f374"}}

alysbrooks avatar Jan 10 '23 00:01 alysbrooks

I forgot to mention it at the time, but you can grab the latest version with the temporary fix (among other improvements):


[lambdaisland/kaocha "1.78.1249"]
{lambdaisland/kaocha {:mvn/version "1.78.1249"}}

alysbrooks avatar Feb 23 '23 04:02 alysbrooks