albertdahlin / elm-posix

Write CLI-scripts in Elm
MIT License
91 stars 6 forks source link

Node crash when reading stdin if stdin is not used #7

Open Erudition opened 4 weeks ago

Erudition commented 4 weeks ago

If elm code uses File.stdIn, which is one of the files without a Result and thus errors can't be handled, text must be passed to stdin of the compiled script or else node will crash.

node:internal/fs/utils:352
    throw err;
    ^

Error: EAGAIN: resource temporarily unavailable, read
    at Object.readSync (node:fs:735:3)
    at tryReadSync (node:fs:420:20)
    at Object.readFileSync (node:fs:471:19)
    at Object.fread (NewProblem.solution:3500:26)
    at Array.<anonymous> (NewProblem.solution:3490:8)
    at Function.f (NewProblem.solution:2228:19)
    at A3 (NewProblem.solution:68:28)
    at Object.b (NewProblem.solution:1987:7)
    at _Scheduler_step (NewProblem.solution:1831:20)
    at _Scheduler_enqueue (NewProblem.solution:1793:3) {
  errno: -11,
  syscall: 'read',
  code: 'EAGAIN'
}

Node.js v20.8.0

Running the script with echo | NewProblem.solution (empty stdin, but it's there) works fine.

AFAICT there's no way to catch this within elm. The node package should probably check for this and just replace the input with nothing.