Skip to content

Commit 8f9d31e

Browse files
committed
fix: Refactor conda--call-json to ignore stderr
Fixes #163. Discards the standard error from the `conda` command, ensuring that it _should_ be more consistently parseable as JSON.
1 parent ce748a5 commit 8f9d31e

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

conda.el

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,24 +170,19 @@ See https://github.com/conda/conda/blob/master/CHANGELOG.md#484-2020-08-06."
170170
(defun conda--call-json (&rest args)
171171
"Call Conda with ARGS, assuming we return JSON."
172172
(let* ((conda (conda--get-executable-path))
173-
(fmt (format "shell.%s+json" (if (eq system-type 'windows-nt) "cmd.exe" "posix")))
174-
(process-file-args (append (list conda nil t nil) args))
175-
(output (with-output-to-string
176-
(with-current-buffer
177-
standard-output
178-
(apply #'process-file process-file-args)))))
173+
(output (with-temp-buffer
174+
;; We set the `destination' to ignore stderr -- this may come
175+
;; back to bite us if anything important is communicated
176+
;; there
177+
(apply #'call-process
178+
(append (list conda nil '(t nil) nil) args))
179+
(buffer-string))))
179180
(condition-case err
180-
;; (if (version< emacs-version "27.1")
181-
;; (json-read-from-string output)
182-
;; (json-parse-string output :object-type 'alist :null-object nil))
183-
(if (progn
184-
(require 'json)
185-
(fboundp 'json-parse-string))
186-
(json-parse-string output :object-type 'alist :null-object nil)
181+
(if (and (require 'json) (fboundp 'json-parse-string))
182+
(json-parse-string output :object-type 'alist :null-object nil)
187183
(json-read-from-string output))
188184
(error "Could not parse %s as JSON: %s" output err))))
189185

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

0 commit comments

Comments
 (0)