DanielXMoore / Civet

A TypeScript superset that favors more types and less typing
https://civet.dev
MIT License
1.36k stars 29 forks source link

CLI avoid errors when output pipe gets closed #1213

Closed edemaine closed 5 months ago

edemaine commented 5 months ago

Tested on Windows and Linux, with

civet -c - <source/main.civet | head -5

Previously we got error messages like

const o=[Object.preventExtensions({"o":unode:events:496
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:94:16)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (node:internal/streams/destroy:169:8)
    at emitErrorCloseNT (node:internal/streams/destroy:128:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -32,
  code: 'EPIPE',
  syscall: 'write'
}

Node.js v20.12.2

or

node:events:497
      throw er; // Unhandled 'error' event
      ^

Error: EOF: end of file, write
    at Socket._write (node:internal/net:61:18)
    at writeOrBuffer (node:internal/streams/writable:564:12)
    at _write (node:internal/streams/writable:493:10)
    at Writable.write (node:internal/streams/writable:502:10)
    at cli (C:\Users\edemaine\Projects\Civet\dist\civet:508:26)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (node:internal/streams/destroy:169:8)
    at emitErrorCloseNT (node:internal/streams/destroy:128:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -4095,
  syscall: 'write',
  code: 'EOF'
}

Node.js v21.7.3
edemaine commented 5 months ago

Currently I'm just hiding two error messages that I've seen in this piping situation: EOF and EPIPE. So any other error messages should still be passed through. In particular ENOSPC seems to be what would happen when the disk is full (but I haven't tested, as it's not very easy to).

bbrk24 commented 5 months ago

Shouldn't -o /dev/full produce the "drive full" error?

Edit: this does indeed produce ENOSPC on my device:

$ npx civet -c in.civet -o /dev/full
/dev/full failed to write:
[Error: ENOSPC: no space left on device, write] {
  errno: -28,
  code: 'ENOSPC',
  syscall: 'write'
}