Skip to content

Commit

Permalink
on non-zero exit display stderr in message area
Browse files Browse the repository at this point in the history
Instead of throwing an error (which disables direnv-mode for all
buffers), display the stderr of direnv in the status line.

If an envrc was not yet allowed, this will provide a better user
experience, prompting the user with a message that is easy to ignore.
  • Loading branch information
Profpatsch committed Mar 5, 2019
1 parent 6cf079f commit 837bafe
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions direnv.el
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,20 @@ In these modes, direnv will use `default-directory' instead of
(setq direnv--installed (direnv--detect)))
(unless direnv--installed
(user-error "Could not find the direnv executable. Is exec-path correct?"))
(let ((environment process-environment))
(let ((environment process-environment)
;; call-process can only output stderr to file
(stderr-tempfile (make-temp-file "direnv-stderr")))
(with-current-buffer (get-buffer-create direnv--output-buffer-name)
(erase-buffer)
(let* ((default-directory directory)
(process-environment environment)
(exit-code (call-process "direnv" nil '(t t) nil "export" "json")))
(exit-code (call-process "direnv" nil `(t ,stderr-tempfile) nil "export" "json")))
(unless (zerop exit-code)
(display-buffer (current-buffer))
(error "Error running direnv: exit code %s; output is in buffer '%s'"
exit-code direnv--output-buffer-name))
(with-temp-buffer
(insert-file-contents stderr-tempfile)
(delete-file stderr-tempfile)
(message "direnv exited %s:\n%s"
exit-code (buffer-string))))
(unless (zerop (buffer-size))
(goto-char (point-max))
(re-search-backward "^{")
Expand Down

0 comments on commit 837bafe

Please sign in to comment.