From 05de0c8f0cf336d90c044446aaa066ee13001b83 Mon Sep 17 00:00:00 2001 From: Rami Chowdhury Date: Sat, 5 Oct 2024 16:13:56 -0400 Subject: [PATCH] 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. --- conda.el | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/conda.el b/conda.el index 5a13c61..43c13cb 100644 --- a/conda.el +++ b/conda.el @@ -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.")