The error is likely from https://github.com/rcaloras/bash-preexec which is included in the shell integration for the MacOS terminal emulator https://www.iterm2.com/ . The above solution works of unsetting PROMPT_COMMAND works; a better solution is to identify which shell script is causing the problem. If it is iTerm2, simply stop .bash{,_profile}
sourcing the iterm integration.
Maybe an iTerm2 shell integration bug? It should check better whether iterm2 is the parent terminal, or give up if it is a terminal multiplexer such as tmux or screen. Personally, I found the iterm2 integration added complexity and confusion like this, and didn't make my life easier.
You may wish to only source the iterm2 integration if not in a multiplexer, and when iterm2 is not a parent terminal. Left as exercise for reader, or iTerm2 developers.