Subject: [PATCH] Fix volume refresh bug in mpc
From: john muhl <[email-masked]>
To: [email-masked]
Date: Sun, 28 Jan 2024 14:17:31 -0600
List-Id: <debbugs-submit.debbugs.gnu.org>

Tags: patch

When mpd is stopped or paused the volume returned is nil which
causes the string-to-number in mpc-volume-refresh to error.

  emacs -Q
  M-x toggle-debug-on-error
  M-: (setopt mpc-host "hifi.lan")
  M-x mpc
  …with something in the playlist
  M-: (mpc-play)
  M-: (mpc-stop)

  Debugger entered--Lisp error: (wrong-type-argument stringp nil)
    string-to-number(nil)
    (mpc-volume-widget (string-to-number (cdr (assq 'volume mpc-status))))
    (setq mpc-volume (mpc-volume-widget (string-to-number (cdr (assq 'volume mpc-status)))))
    mpc-volume-refresh()
    funcall(mpc-volume-refresh)
    (progn (funcall (cdr pair)))
    (if (or (eq t (car pair)) (not (equal (cdr (assq (car pair) old-status)) (cdr (assq (car pair) mpc-status))))) (progn (funcall (cdr pair))))
    (let ((pair (car tail))) (if (or (eq t (car pair)) (not (equal (cdr (assq (car pair) old-status)) (cdr (assq (car pair) mpc-status))))) (progn (funcall (cdr pair)))) (setq tail (cdr tail)))
    (while tail (let ((pair (car tail))) (if (or (eq t (car pair)) (not (equal (cdr (assq ... old-status)) (cdr (assq ... mpc-status))))) (progn (funcall (cdr pair)))) (setq tail (cdr tail))))
    (let ((tail mpc-status-callbacks)) (while tail (let ((pair (car tail))) (if (or (eq t (car pair)) (not (equal (cdr ...) (cdr ...)))) (progn (funcall (cdr pair)))) (setq tail (cdr tail)))))
    (if (equal old-status mpc-status) nil (let ((tail mpc-status-callbacks)) (while tail (let ((pair (car tail))) (if (or (eq t (car pair)) (not (equal ... ...))) (progn (funcall (cdr pair)))) (setq tail (cdr tail))))))
    (let ((old-status mpc-status)) (setq mpc-status (mpc-proc-buf-to-alist)) (progn (or mpc-status (cl--assertion-failed 'mpc-status)) nil) (if (equal old-status mpc-status) nil (let ((tail mpc-status-callbacks)) (while tail (let ((pair (car tail))) (if (or (eq t ...) (not ...)) (progn (funcall ...))) (setq tail (cdr tail)))))))
    mpc--status-callback()
    (closure ((cb)) nil (mpc--status-callback) (if cb (funcall cb)))()
    funcall((closure ((cb)) nil (mpc--status-callback) (if cb (funcall cb))))
    (let ((callback (process-get proc 'callback))) (process-put proc 'callback nil) (if error-text (process-put proc 'mpc-proc-error error-text)) (funcall callback))
    (let ((error-text (match-string 1))) (delete-region (point) (point-max)) (let ((callback (process-get proc 'callback))) (process-put proc 'callback nil) (if error-text (process-put proc 'mpc-proc-error error-text)) (funcall callback)))
    (progn (process-put proc 'ready t) (if (eq (match-end 0) (point-max)) nil (error "Unexpected trailing text")) (let ((error-text (match-string 1))) (delete-region (point) (point-max)) (let ((callback (process-get proc 'callback))) (process-put proc 'callback nil) (if error-text (process-put proc 'mpc-proc-error error-text)) (funcall callback))))
    (if (and (< start (point)) (re-search-backward mpc--proc-end-re start t)) (progn (process-put proc 'ready t) (if (eq (match-end 0) (point-max)) nil (error "Unexpected trailing text")) (let ((error-text (match-string 1))) (delete-region (point) (point-max)) (let ((callback (process-get proc 'callback))) (process-put proc 'callback nil) (if error-text (process-put proc 'mpc-proc-error error-text)) (funcall callback)))))
    (let ((start (or (marker-position (process-mark proc)) (point-min)))) (goto-char start) (insert string) (move-marker (process-mark proc) (point)) (beginning-of-line) (if (and (< start (point)) (re-search-backward mpc--proc-end-re start t)) (progn (process-put proc 'ready t) (if (eq (match-end 0) (point-max)) nil (error "Unexpected trailing text")) (let ((error-text (match-string 1))) (delete-region (point) (point-max)) (let ((callback (process-get proc ...))) (process-put proc 'callback nil) (if error-text (process-put proc 'mpc-proc-error error-text)) (funcall callback))))))
    (save-excursion (let ((start (or (marker-position (process-mark proc)) (point-min)))) (goto-char start) (insert string) (move-marker (process-mark proc) (point)) (beginning-of-line) (if (and (< start (point)) (re-search-backward mpc--proc-end-re start t)) (progn (process-put proc 'ready t) (if (eq (match-end 0) (point-max)) nil (error "Unexpected trailing text")) (let ((error-text (match-string 1))) (delete-region (point) (point-max)) (let ((callback ...)) (process-put proc 'callback nil) (if error-text (process-put proc ... error-text)) (funcall callback)))))))
    (if (process-get proc 'ready) (if nil nil (delete-process proc) (set-process-buffer proc nil) (pop-to-buffer (clone-buffer)) (error "MPD output while idle!?")) (save-excursion (let ((start (or (marker-position (process-mark proc)) (point-min)))) (goto-char start) (insert string) (move-marker (process-mark proc) (point)) (beginning-of-line) (if (and (< start (point)) (re-search-backward mpc--proc-end-re start t)) (progn (process-put proc 'ready t) (if (eq (match-end 0) (point-max)) nil (error "Unexpected trailing text")) (let ((error-text ...)) (delete-region (point) (point-max)) (let (...) (process-put proc ... nil) (if error-text ...) (funcall callback))))))))
    (save-current-buffer (set-buffer (process-buffer proc)) (if (process-get proc 'ready) (if nil nil (delete-process proc) (set-process-buffer proc nil) (pop-to-buffer (clone-buffer)) (error "MPD output while idle!?")) (save-excursion (let ((start (or (marker-position ...) (point-min)))) (goto-char start) (insert string) (move-marker (process-mark proc) (point)) (beginning-of-line) (if (and (< start (point)) (re-search-backward mpc--proc-end-re start t)) (progn (process-put proc 'ready t) (if (eq ... ...) nil (error "Unexpected trailing text")) (let (...) (delete-region ... ...) (let ... ... ... ...))))))))
    mpc--proc-filter(#<process MPC> "repeat: 0\nrandom: 1\nsingle: 0\nconsume: 0\npartition: default\nplaylist: 55708\nplaylistlength: 0\nmixrampdb: 0\nstate: stop\nOK\n")

In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.38, cairo version 1.18.0) of 2024-01-21 built on thelio
Repository revision: 9364c28959a5b00e8ffd5d0d283ff0c0042f1bb0
Repository branch: master
System Description: Fedora Linux 39 (Thirty Nine)

Configured using:
 'configure --with-pgtk --prefix=/home/jm/.local'