Skip to content

Commit

Permalink
fix: Refactor conda--call-json to ignore stderr
Browse files Browse the repository at this point in the history
Fixes #163. Discards the standard error from the `conda` command,
ensuring that it _should_ be more consistently parseable as JSON.
  • Loading branch information
necaris committed Oct 5, 2024
1 parent b124387 commit 05de0c8
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions conda.el
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,19 @@ See https://github.com/conda/conda/blob/master/CHANGELOG.md#484-2020-08-06."
(defun conda--call-json (&rest args)
"Call Conda with ARGS, assuming we return JSON."
(let* ((conda (conda--get-executable-path))
(process-file-args (append (list conda nil t nil) args))
(output (with-output-to-string
(with-current-buffer
standard-output
(apply #'process-file process-file-args)))))
(output (with-temp-buffer
;; We set the `destination' to ignore stderr -- this may come
;; back to bite us if anything important is communicated
;; there
(apply #'call-process
(append (list conda nil '(t nil) nil) args))
(buffer-string))))
(condition-case err
(if (progn
(require 'json)
(fboundp 'json-parse-string))
(json-parse-string output :object-type 'alist :null-object nil)
(if (and (require 'json) (fboundp 'json-parse-string))
(json-parse-string output :object-type 'alist :null-object nil)
(json-read-from-string output))
(error "Could not parse %s as JSON: %s" output err))))


(defvar conda--config nil
"Cached copy of configuration that Conda sees (including `condarc', etc).
Set for the lifetime of the process.")
Expand Down

0 comments on commit 05de0c8

Please sign in to comment.