Effekt v0.2.2 crashes on Windows
Steps to reproduce:
- Use Windows
- Install Effekt v0.2.2
- Open Effekt REPL
- Write
42and press Enter. - See the error message below.
Error message
The error message points to the fact that we added a setPosixFilePermissions to our Kiama fork a few months ago in commit https://github.com/effekt-lang/kiama/commit/89515c8d17c2772d1caba6f1ef7a9ff5d1d93022:
Exception in thread "main" java.lang.UnsupportedOperationException
at java.base/java.nio.file.Files.setPosixFilePermissions(Files.java:2168)
at kiama.util.IO$.createFile(IO.scala:81)
at effekt.JSRunner$.build(Runner.scala:131)
at effekt.JSRunner$.build(Runner.scala:124)
at effekt.Runner.eval(Runner.scala:58)
at effekt.Runner.eval$(Runner.scala:14)
How to resolve
We should at least catch the UnsupportedOperationException.
If we want, we might be able to use AclFileAttributeView on Windows or just fallback to java.io.File.setExecutable().
Note that although it's technically an issue in our Kiama fork, I'm filing it here for visibility (and in order to expedite it). :)
But wait, there's more! Even if you work around the UnsupportedOperationException like this:
def createFile(filename: String, content: String, executable: Boolean = false): Unit = {
val writer = filewriter(filename)
writer.write(content)
writer.close()
try {
if (executable) {
val pPath = Path.of(filename)
+ try {
val perms = Set(
OWNER_READ, OWNER_WRITE, OWNER_EXECUTE,
GROUP_READ,
OTHERS_READ
)
Files.setPosixFilePermissions(pPath, SetHasAsJava(perms).asJava)
+ } catch { case e: java.lang.UnsupportedOperationException => () }
}
writer.write(content)
} finally {
writer.close()
}
}
then neither the REPL nor the compiler work on Windows as we create a file with a shebang:
#!/usr/bin/env node
require(...).main()
and then try to execute it, which on Windows throws:
java.io.IOException: Cannot run program ...: CreateProcess error=193 (%1 is not a valid Win32 app).
I've also verified that this is, in fact, a regression from v0.2.1 as there, Effekt creates a JavaScript file directly (which does work on Windows, both in the REPL and as a compiler).