opencommit: Error after generating commit : ERR_TTY_INIT_FAILED

Config: VS Code on Windows 11

Getting error ERR_TTY_INIT_FAILED when generating commit.

β””  Commit message:
β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
fix(AppMailUseCase.ts): add notEmpty filter to notifications array in deleteMail method
β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

node:internal/errors:477
    ErrorCaptureStackTrace(err);
    ^

SystemError [ERR_TTY_INIT_FAILED]: TTY initialization failed: uv_tty_init returned EBADF (bad file descriptor)
    at new SystemError (node:internal/errors:238:5)
    at new NodeError (node:internal/errors:349:7)
    at new WriteStream (node:tty:94:11)
    at sD2.prompt (C:\Users\svad\AppData\Roaming\npm\node_modules\opencommit\out\cli.cjs:15719:16)
    at Q3 (C:\Users\svad\AppData\Roaming\npm\node_modules\opencommit\out\cli.cjs:15891:8)
    at generateCommitMessageFromGitDiff (C:\Users\svad\AppData\Roaming\npm\node_modules\opencommit\out\cli.cjs:17756:41)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async commit (C:\Users\svad\AppData\Roaming\npm\node_modules\opencommit\out\cli.cjs:17807:3) {
  code: 'ERR_TTY_INIT_FAILED',
  info: {
    errno: -4083,
    code: 'EBADF',
    message: 'bad file descriptor',
    syscall: 'uv_tty_init'
  },
  errno: [Getter/Setter],
  syscall: [Getter/Setter]
}

I have same error when using command oc, or using VS Code commit button with git hook set.

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 3
  • Comments: 15 (6 by maintainers)

Most upvoted comments

I tried digging into this, and it seems like the cause is because of how isHookCalled checks if process.argv[1] ends with SYMLINK_URL. As seen here. To be exact, the problem is SYMLINK_URL use forward slash, while in windows, file path uses backslash as delimiter, thus isHookCalled is false even though it does called from a hook, and cli run commit() instead of prepareCommitMessageHook().

I think there are some way to solve this problem, but the two solutions that I tested is to check process.argv[1] properly according to the platform where the program is currently running in, simply by checking if process.platform is win32.

And the other solution is to change isHookCalled to check process.stdin.isTTY instead, because inside pre-commit or prepare-commit-msg hook there is no user interactivity (I couldn’t find the documentation for it, but it’s a common problem when I googled it). And from my test, process.stdin.isTTY is undefined when I ran git commit, and its true when I ran npm run dev -- commit, so it is as expected.

In both solutions, git commit called the hook with no error, and the generated message inserted to COMMIT_EDITMSG as expected.

Thanks @hufuhufu for the RCA. I like the idea of checking the platform first. I have a windows machine I can test this on will push the change with #48

will try to add this asap, thanks @hufuhufu ❀️ ❀️