The error is raised by
shell-command--shell-command-with-editor-mode. But further stack trace is obfuscated by bytecompiled output. Recently I had to set
(setq explicit-shell-file-name "bash")
to be able to run M-x
shell (it would give a similar error). I think this may be related, but I cannot find what exactly is broken.
This is Ubuntu 16.04.