Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error after generating commit : ERR_TTY_INIT_FAILED #11

Open
svadhis opened this issue Mar 13, 2023 · 15 comments
Open

Error after generating commit : ERR_TTY_INIT_FAILED #11

svadhis opened this issue Mar 13, 2023 · 15 comments

Comments

@svadhis
Copy link

svadhis commented Mar 13, 2023

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.

@svadhis
Copy link
Author

svadhis commented Mar 13, 2023

I have this error only when git hook is set

@DylanDelobel
Copy link

Same error with git hook set

@di-sukharev
Copy link
Owner

@svadhis @DylanDelobel hi

do you guys have windows?

@di-sukharev
Copy link
Owner

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
Copy link

@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
Copy link

I am also getting the same error on windows.

@di-sukharev
Copy link
Owner

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
Copy link

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
Copy link
Owner

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

@matt-degraffenreid
Copy link
Contributor

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
Copy link
Contributor

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
Copy link

cforce commented Apr 18, 2023

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
Copy link

Stale issue message

@cforce
Copy link

cforce commented Jun 12, 2023

reopen ..never ahs been solved

@scottdotau
Copy link

scottdotau commented Mar 15, 2024

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)

typicode/husky#850 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants