0

I am trying to get husky to launch commitizen in a pre-commit hook. Works fine on Linux. On Mac, not so much.

#!/bin/bash
exec < /dev/tty && cz commit || true

It looks like polling is broken on Mac because this causes CZ to crash, and the errors seem related to polling keyboard input and not being able to set up an event delegate.

Has anyone cracked this on Mac and how did you get around this thorny problem?

Edit: The stack trace from my machine"

Traceback (most recent call last):
  File "/opt/homebrew/bin/cz", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/opt/homebrew/Cellar/commitizen/4.5.1/libexec/lib/python3.13/site-packages/commitizen/cli.py", line 656, in main
    args.func(conf, arguments)()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/opt/homebrew/Cellar/commitizen/4.5.1/libexec/lib/python3.13/site-packages/commitizen/commands/commit.py", line 127, in __call__
    m = self.prompt_commit_questions()
  File "/opt/homebrew/Cellar/commitizen/4.5.1/libexec/lib/python3.13/site-packages/commitizen/commands/commit.py", line 58, in prompt_commit_questions
    answers = questionary.prompt(questions, style=cz.style)
  File "/opt/homebrew/Cellar/commitizen/4.5.1/libexec/lib/python3.13/site-packages/questionary/prompt.py", line 78, in prompt
    return unsafe_prompt(questions, answers, patch_stdout, true_color, **kwargs)
  File "/opt/homebrew/Cellar/commitizen/4.5.1/libexec/lib/python3.13/site-packages/questionary/prompt.py", line 221, in unsafe_prompt
    answer = question.unsafe_ask(patch_stdout)
  File "/opt/homebrew/Cellar/commitizen/4.5.1/libexec/lib/python3.13/site-packages/questionary/question.py", line 89, in unsafe_ask
    return self.application.run()
           ~~~~~~~~~~~~~~~~~~~~^^
  File "/opt/homebrew/Cellar/commitizen/4.5.1/libexec/lib/python3.13/site-packages/prompt_toolkit/application/application.py", line 1002, in run
    return asyncio.run(coro)
           ~~~~~~~~~~~^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.2/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.2/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.2/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/opt/homebrew/Cellar/commitizen/4.5.1/libexec/lib/python3.13/site-packages/prompt_toolkit/application/application.py", line 886, in run_async
    return await _run_async(f)
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/commitizen/4.5.1/libexec/lib/python3.13/site-packages/prompt_toolkit/application/application.py", line 734, in _run_async
    with self.input.raw_mode(), self.input.attach(
                                ~~~~~~~~~~~~~~~~~^
        read_from_input_in_context
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
    ), attach_winch_signal_handler(self._on_resize):
    ^
  File "/opt/homebrew/Cellar/[email protected]/3.13.2/Frameworks/Python.framework/Versions/3.13/lib/python3.13/contextlib.py", line 141, in __enter__
    return next(self.gen)
  File "/opt/homebrew/Cellar/commitizen/4.5.1/libexec/lib/python3.13/site-packages/prompt_toolkit/input/vt100.py", line 165, in _attached_input
    loop.add_reader(fd, callback_wrapper)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.2/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/selector_events.py", line 347, in add_reader
    self._add_reader(fd, callback, *args)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.2/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/selector_events.py", line 279, in _add_reader
    self._selector.register(fd, selectors.EVENT_READ,
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
                            (handle, None))
                            ^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.13.2/Frameworks/Python.framework/Versions/3.13/lib/python3.13/selectors.py", line 505, in register
    self._selector.control([kev], 0, 0)
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
OSError: [Errno 22] Invalid argument
11
  • MacOS has a much older version of bash than Linux. Commented Apr 15 at 19:07
  • I'm not familiar with Commitizen, but why can't you just do cz commit < /dev/tty? Commented Apr 15 at 19:08
  • @Barmar, ...that's true, but on this two-line script I can't see what would have changed; this exec usage existed back then. Commented Apr 15 at 19:47
  • 1
    It would improve the question to have the details of the "crash" -- what specific error message did it emit to lead you to think that "polling is broken"? Show, don't tell. Commented Apr 15 at 19:48
  • 1
    That should certainly be included in the text of the question itself. Commented Apr 15 at 21:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.