opencommit: Error after generating commit : ERR_TTY_INIT_FAILED
Config: VS Code on Windows 11
Getting error ERR_TTY_INIT_FAILED when generating commit.
[90mβ[39m 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)
I tried digging into this, and it seems like the cause is because of how
isHookCalledchecks ifprocess.argv[1]ends withSYMLINK_URL. As seen here. To be exact, the problem isSYMLINK_URLuse forward slash, while in windows, file path uses backslash as delimiter, thusisHookCalledisfalseeven though it does called from a hook, and cli runcommit()instead ofprepareCommitMessageHook().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 ifprocess.platformiswin32.And the other solution is to change
isHookCalledto checkprocess.stdin.isTTYinstead, because insidepre-commitorprepare-commit-msghook 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.isTTYisundefinedwhen I rangit commit, and itstruewhen I rannpm run dev -- commit, so it is as expected.In both solutions,
git commitcalled the hook with no error, and the generated message inserted toCOMMIT_EDITMSGas 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 β€οΈ β€οΈ