di-sukharev / opencommit

Generate conventional git commit messages with AI in 1 second 🤯🔫
https://www.npmjs.com/package/opencommit
MIT License
6.15k stars 328 forks source link

Error after generating commit : ERR_TTY_INIT_FAILED #11

Open svadhis opened 1 year ago

svadhis commented 1 year ago

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.

svadhis commented 1 year ago

I have this error only when git hook is set

DylanDelobel commented 1 year ago

Same error with git hook set

di-sukharev commented 1 year ago

@svadhis @DylanDelobel hi

do you guys have windows?

di-sukharev commented 1 year ago

ok i see, it's windows, i dont have one, so hard to reproduce and debug, maybe one of you want to solve it and make a PR?

DylanDelobel commented 1 year ago

@di-sukharev Yes for Windows as env

I have hard time to track down what going bad but yeah I will make a PR if I found a fix

Mutahhar commented 1 year ago

I am also getting the same error on windows.

di-sukharev commented 1 year ago

yep, hook on windows looks like not working properly. @Mutahhar @DylanDelobel you could fork the repo and run code locally with npm run dev -- hook set and npm run dev -- commit to see the error log

hufuhufu commented 1 year ago

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.

di-sukharev commented 1 year ago

will try to add this asap, thanks @hufuhufu <3 <3

matt-degraffenreid commented 1 year ago

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

matt-degraffenreid commented 1 year ago

So the path module is platform independent. By default, the path module automatically switches between POSIX (OSX, Linux) and Windows modes based on which OS your Node process is running. Simply switch to path.join instead of specifying the delimiters should resolve the issue.

cforce commented 1 year ago

On dev dev branch there seems to be another windows incompatible mod used (venv) PS C:\develop\git\openai\opencommit> npm install -g dev npm ERR! code EBADPLATFORM npm ERR! notsup Unsupported platform for inotify@1.4.6: wanted {"os":"linux"} (current: {"os":"win32","arch":"x64"}) npm ERR! notsup Valid OS: linux npm ERR! notsup Valid Arch: undefined npm ERR! notsup Actual OS: win32 npm ERR! notsup Actual Arch: x64

github-actions[bot] commented 1 year ago

Stale issue message

cforce commented 1 year ago

reopen ..never ahs been solved

scottdotau commented 8 months ago

I'm running into a similar problem (though Yarn on Linux).

While looking for answers I stumbled on this, which may provide some answers/clues (even though it's for Husky, looks quite similar)

https://github.com/typicode/husky/issues/850#issuecomment-774231951