emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 34fe0b5c87c 3/5: Replace some uses of erc-error


From: F. Jason Park
Subject: master 34fe0b5c87c 3/5: Replace some uses of erc-error
Date: Sat, 23 Dec 2023 09:51:10 -0500 (EST)

branch: master
commit 34fe0b5c87ca991436d999d451276838529c96c2
Author: F. Jason Park <jp@neverwas.me>
Commit: F. Jason Park <jp@neverwas.me>

    Replace some uses of erc-error
    
    * lisp/erc/erc-button.el
    (erc-button--display-error-notice-with-keys-and-warn): Use
    `erc--lwarn' so the warnings buffer is overridable for testing.
    * lisp/erc/erc-sasl.el (erc-sasl-mode, erc-sasl-enable): Signal an
    `error' instead of calling `erc-error', which continues execution.  In
    this special case, the session cannot continue initializing, since
    connection registration can't reasonably be expected to complete
    successfully.
    (erc-sasl--destroy): Don't run `erc-quit-hook', and issue a warning of
    level `:error' to get users' attention instead of calling `ding'.
    * lisp/erc/erc-speedbar.el
    (erc-speedbar--emulate-sidebar-set-window-preserve-size): Don't set
    window parameters.  Doing this basically made
    `erc-speedbar-toggle-nicknames-window-lock' unusable.
    (erc-speedbar--toggle-nicknames-sidebar): Manually unlock the window
    after toggling.
    (erc-nickbar-mode, erc-nickbar-enable, erc-nickbar-disable): Don't
    `ding' when called in a non-ERC buffer, and make sure to call
    `erc-speedbar--ensure' from an ERC buffer.  Also, don't disable
    minor-mode var when speedbar buffer doesn't exist because that doesn't
    ensure it'll be created the next time around, and users may count on
    the activation state remaining consistent.
    (erc-speedbar-toggle-nicknames-window-lock): Make usable from lisp
    with explicit numeric arg.
    * lisp/erc/erc-status-sidebar.el (erc-bufbar-mode, erc-bufbar-enable):
    Only create the side window from an erc-mode buffer to ensure the
    ratio is preserved when burying the current buffer, e.g., with
    `custom-buffer-done'.
    * lisp/erc/erc.el (erc--warnings-buffer-name, erc--lwarn): New
    function, an analog of `lwarn', that allows for overriding the
    warnings buffer with the new variable `erc--warnings-buffer-name'.
    (erc-cmd-SERVER): Add comment.
    * test/lisp/erc/erc-scenarios-sasl.el
    (erc-scenarios-sasl--plain-fail): Expect warning instead of error.
    * test/lisp/erc/erc-scenarios-status-sidebar.el
    (erc-scenarios-status-sidebar--bufbar): Refresh when interactive as
    well.
    * test/lisp/erc/resources/sasl/plain-failed.eld: Expect EOF instead of
    "CAP END".  (Bug#63595)
---
 lisp/erc/erc-button.el                        |  4 +--
 lisp/erc/erc-sasl.el                          |  9 ++++---
 lisp/erc/erc-speedbar.el                      | 39 ++++++++++++++-------------
 lisp/erc/erc-status-sidebar.el                | 13 ++++-----
 lisp/erc/erc.el                               | 11 ++++++++
 test/lisp/erc/erc-scenarios-sasl.el           | 34 ++++++++++++-----------
 test/lisp/erc/erc-scenarios-status-sidebar.el |  3 +--
 test/lisp/erc/resources/sasl/plain-failed.eld | 10 +++----
 8 files changed, 70 insertions(+), 53 deletions(-)

diff --git a/lisp/erc/erc-button.el b/lisp/erc/erc-button.el
index d27aa299df2..a62dd520860 100644
--- a/lisp/erc/erc-button.el
+++ b/lisp/erc/erc-button.el
@@ -869,8 +869,8 @@ non-strings, concatenate leading string members before 
applying
       (with-syntax-table lisp-mode-syntax-table
         (skip-syntax-forward "^-"))
       (forward-char)
-      (display-warning
-       'erc (buffer-substring-no-properties (point) (point-max))))))
+      (erc--lwarn
+       'erc :warning (buffer-substring-no-properties (point) (point-max))))))
 
 (provide 'erc-button)
 
diff --git a/lisp/erc/erc-sasl.el b/lisp/erc/erc-sasl.el
index 8ecce7aef31..ae057f939a3 100644
--- a/lisp/erc/erc-sasl.el
+++ b/lisp/erc/erc-sasl.el
@@ -332,8 +332,8 @@ This doesn't solicit or validate a suite of supported 
mechanisms."
             (client (erc-sasl--create-client mech)))
        (unless client
          (erc-display-error-notice
-          nil (format "Unknown or unsupported SASL mechanism: %s" mech))
-         (erc-error "Unknown or unsupported SASL mechanism: %s" mech))
+          nil (format "Unknown or unsupported SASL mechanism: `%s'" mech))
+         (error "Unknown or unsupported SASL mechanism: `%s'" mech))
        (setf (erc-sasl--state-client erc-sasl--state) client))))
   ((kill-local-variable 'erc-sasl--state)
    (kill-local-variable 'erc-sasl--options))
@@ -370,9 +370,10 @@ This doesn't solicit or validate a suite of supported 
mechanisms."
           (setq data (concat (substring data end) (and (= end 400) "+"))))))))
 
 (defun erc-sasl--destroy (proc)
-  (run-hook-with-args 'erc-quit-hook proc)
+  "Destroy process PROC and warn user that their settings are likely faulty."
   (delete-process proc)
-  (erc-error "Disconnected from %s; please review SASL settings" proc))
+  (erc--lwarn 'erc-sasl :error
+              "Disconnected from %s; please review SASL settings" proc))
 
 (define-erc-response-handler (902)
   "Handle an ERR_NICKLOCKED response." nil
diff --git a/lisp/erc/erc-speedbar.el b/lisp/erc/erc-speedbar.el
index 90d7376fc0c..91806f47e01 100644
--- a/lisp/erc/erc-speedbar.el
+++ b/lisp/erc/erc-speedbar.el
@@ -453,10 +453,7 @@ The INDENT level is ignored."
          `(display-buffer-in-side-window
            . ((side . right)
               (window-width . ,erc-speedbar-nicknames-window-width)))))
-    (erc-status-sidebar-set-window-preserve-size)
-    (when-let ((window (get-buffer-window speedbar-buffer)))
-      (set-window-parameter window 'no-other-window nil)
-      (internal-show-cursor window t))))
+    (erc-status-sidebar-set-window-preserve-size)))
 
 (defun erc-speedbar--status-sidebar-mode--unhook ()
   "Remove hooks installed by `erc-status-sidebar-mode'."
@@ -504,7 +501,8 @@ The INDENT level is ignored."
                   (speedbar-set-mode-line-format)))
             (when (or (not force) (>= arg 0))
               (with-selected-frame speedbar-frame
-                (erc-speedbar--emulate-sidebar-set-window-preserve-size)))))
+                (erc-speedbar--emulate-sidebar-set-window-preserve-size)
+                (erc-speedbar-toggle-nicknames-window-lock -1)))))
       (when-let (((or (not force) (>= arg 0)))
                  (speedbar-frame-parameters (backquote-list*
                                              '(visibility . nil)
@@ -522,7 +520,8 @@ The INDENT level is ignored."
         ;; Emacs in the meantime.
         (make-frame-invisible speedbar-frame)
         (select-frame (setq speedbar-frame (previous-frame)))
-        (erc-speedbar--emulate-sidebar-set-window-preserve-size))))
+        (erc-speedbar--emulate-sidebar-set-window-preserve-size)
+        (erc-speedbar-toggle-nicknames-window-lock -1))))
   (cl-assert (not (cdr (erc-speedbar--get-timers))) t))
 
 (defun erc-speedbar--ensure (&optional force)
@@ -563,12 +562,10 @@ such a thing and can reproduce it, please file a bug 
report with
                (and-let* ((speedbar-buffer)
                           (win (get-buffer-window speedbar-buffer 'all-frames))
                           ((eq speedbar-frame (window-frame win))))))
-     (if speedbar-buffer
-         (erc-speedbar--ensure 'force)
-       (setq erc-nickbar-mode nil)
-       (when (derived-mode-p 'erc-mode)
-         (erc-error "Not initializing `erc-nickbar-mode' in %s"
-                    (current-buffer))))))
+     (when-let ((buf (or (and (derived-mode-p 'erc-mode) (current-buffer))
+                         (car (erc-buffer-filter #'erc--server-buffer-p)))))
+       (with-current-buffer buf
+         (erc-speedbar--ensure 'force)))))
   ((remove-hook 'erc--setup-buffer-hook #'erc-speedbar--ensure)
    (when erc-track-mode
      (setq erc-track--switch-fallback-blockers
@@ -609,15 +606,21 @@ such a thing and can reproduce it, please file a bug 
report with
     ;; erc-speedbar.el resets this to nil.
     (setq speedbar-buffer nil)))
 
-(defun erc-speedbar-toggle-nicknames-window-lock ()
-  "Toggle whether nicknames window is selectable with \\[other-window]."
-  (interactive)
+(defun erc-speedbar-toggle-nicknames-window-lock (arg)
+  "Toggle whether nicknames window is selectable with \\[other-window].
+When arg is a number, lock the window if non-negative, otherwise
+unlock."
+  (interactive "P")
   (unless erc-nickbar-mode
     (user-error "`erc-nickbar-mode' inactive"))
   (when-let ((window (get-buffer-window speedbar-buffer)))
-    (let ((val (window-parameter window 'no-other-window)))
-      (set-window-parameter window 'no-other-window (not val))
-      (message "nick-window: %s" (if val "selectable" "protected")))))
+    (let ((val (cond ((natnump arg) t)
+                     ((integerp arg) nil)
+                     (t (not (window-parameter window
+                                               'no-other-window))))))
+      (set-window-parameter window 'no-other-window val)
+      (unless (numberp arg)
+        (message "nick-window: %s" (if val "protected" "selectable"))))))
 
 
 ;;;; Nicks integration
diff --git a/lisp/erc/erc-status-sidebar.el b/lisp/erc/erc-status-sidebar.el
index 98d5a321385..2cd74021fe7 100644
--- a/lisp/erc/erc-status-sidebar.el
+++ b/lisp/erc/erc-status-sidebar.el
@@ -257,12 +257,13 @@ current frame only."
          " Add `track' to `erc-modules' to silence this message."))
      (erc-track-mode +1))
    (add-hook 'erc--setup-buffer-hook #'erc-status-sidebar--open)
-   (unless erc--updating-modules-p
-     (if (erc-with-server-buffer erc-server-connected)
-         (erc-status-sidebar--open)
-       (when (derived-mode-p 'erc-mode)
-         (erc-error "Not initializing `erc-bufbar-mode' in %s"
-                    (current-buffer))))))
+   ;; Preserve side-window dimensions after `custom-buffer-done'.
+   (when-let (((not erc--updating-modules-p))
+              (buf (or (and (derived-mode-p 'erc-mode) (current-buffer))
+                       (car (erc-buffer-filter
+                             (lambda () erc-server-connected))))))
+     (with-current-buffer buf
+       (erc-status-sidebar--open))))
   ((remove-hook 'erc--setup-buffer-hook #'erc-status-sidebar--open)
    (erc-status-sidebar-close 'all-frames)
    (when-let ((arg erc--module-toggle-prefix-arg)
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 241e260e518..64629026704 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -2880,6 +2880,15 @@ message instead, to make debugging easier."
     (apply #'message args)
     (beep)))
 
+(defvar erc--warnings-buffer-name nil
+  "Name of possibly existing alternate warnings buffer for unit tests.")
+
+(defun erc--lwarn (type level format-string &rest args)
+  "Issue a warning of TYPE and LEVEL with FORMAT-STRING and ARGS."
+  (let ((message (substitute-command-keys
+                  (apply #'format-message format-string args))))
+    (display-warning type message level erc--warnings-buffer-name)))
+
 ;;; Debugging the protocol
 
 (defvar erc-debug-irc-protocol-time-format "%FT%T.%6N%z "
@@ -5032,6 +5041,8 @@ connection or, with -A, all applicable connections.
 
 (put 'erc-cmd-RECONNECT 'process-not-needed t)
 
+;; FIXME use less speculative error message or lose `condition-case',
+;; since most connection failures don't signal anything.
 (defun erc-cmd-SERVER (server)
   "Connect to SERVER, leaving existing connection intact."
   (erc-log (format "cmd: SERVER: %s" server))
diff --git a/test/lisp/erc/erc-scenarios-sasl.el 
b/test/lisp/erc/erc-scenarios-sasl.el
index ab652d72dd2..74075b1aaf3 100644
--- a/test/lisp/erc/erc-scenarios-sasl.el
+++ b/test/lisp/erc/erc-scenarios-sasl.el
@@ -149,23 +149,25 @@
        (erc-modules (cons 'sasl erc-modules))
        (erc-sasl-password "wrong")
        (erc-sasl-mechanism 'plain)
-       (expect (erc-d-t-make-expecter))
-       (buf nil))
+       (erc--warnings-buffer-name  "*ERC test warnings*")
+       (warnings-buffer (get-buffer-create erc--warnings-buffer-name))
+       (expect (erc-d-t-make-expecter)))
 
-    (ert-info ("Connect")
-      (setq buf (erc :server "127.0.0.1"
-                     :port port
-                     :nick "tester"
-                     :user "tester"
-                     :full-name "tester"))
-      (let ((err (should-error
-                  (with-current-buffer buf
-                    (funcall expect 20 "Connection failed!")))))
-        (should (string-search "please review" (cadr err)))
-        (with-current-buffer buf
-          (funcall expect 10 "Opening connection")
-          (funcall expect 20 "SASL authentication failed")
-          (should-not (erc-server-process-alive)))))))
+    (with-current-buffer (erc :server "127.0.0.1"
+                              :port port
+                              :nick "tester"
+                              :user "tester"
+                              :full-name "tester")
+      (funcall expect 10 "Opening connection")
+      (funcall expect 20 "SASL authentication failed")
+      (funcall expect 20 "Connection failed!")
+      (should-not (erc-server-process-alive)))
+
+    (with-current-buffer warnings-buffer
+      (funcall expect 10 "please review SASL settings")))
+
+  (when noninteractive
+    (should-not (get-buffer "*ERC test warnings*"))))
 
 (defun erc-scenarios--common--sasl (mech)
   (erc-scenarios-common-with-cleanup
diff --git a/test/lisp/erc/erc-scenarios-status-sidebar.el 
b/test/lisp/erc/erc-scenarios-status-sidebar.el
index 3a047bf3983..b2b6351e333 100644
--- a/test/lisp/erc/erc-scenarios-status-sidebar.el
+++ b/test/lisp/erc/erc-scenarios-status-sidebar.el
@@ -64,8 +64,7 @@
         (let ((obuf (window-buffer))) ; *scratch*
           (set-window-buffer (selected-window) "#foo")
           (erc-d-t-wait-for 5
-              (when noninteractive
-                (erc-status-sidebar-refresh))
+              (erc-status-sidebar-refresh)
             (with-current-buffer "*ERC Status*"
               (and (marker-position erc-status-sidebar--active-marker)
                    (goto-char erc-status-sidebar--active-marker)
diff --git a/test/lisp/erc/resources/sasl/plain-failed.eld 
b/test/lisp/erc/resources/sasl/plain-failed.eld
index 336700290c5..47d13de18e5 100644
--- a/test/lisp/erc/resources/sasl/plain-failed.eld
+++ b/test/lisp/erc/resources/sasl/plain-failed.eld
@@ -1,16 +1,16 @@
 ;; -*- mode: lisp-data; -*-
 ((cap-req 10 "CAP REQ :sasl"))
-((nick 1 "NICK tester"))
-((user 1 "USER tester 0 * :tester")
+((nick 10 "NICK tester"))
+((user 10 "USER tester 0 * :tester")
  (0.0 ":irc.foonet.org NOTICE * :*** Looking up your hostname...")
  (0.0 ":irc.foonet.org NOTICE * :*** Found your hostname")
  (0.0 ":irc.foonet.org CAP * ACK :cap-notify sasl"))
 
-((authenticate-plain 3.2 "AUTHENTICATE PLAIN")
+((authenticate-plain 10 "AUTHENTICATE PLAIN")
  (0.0 ":irc.foonet.org AUTHENTICATE +"))
 
-((authenticate-gimme 3.2 "AUTHENTICATE AHRlc3RlcgB3cm9uZw==")
+((authenticate-gimme 10 "AUTHENTICATE AHRlc3RlcgB3cm9uZw==")
  (0.0 ":irc.foonet.org 900 * * tester :You are now logged in as tester")
  (0.0 ":irc.foonet.org 904 * :SASL authentication failed: Invalid account 
credentials"))
 
-((cap-end 3.2 "CAP END"))
+((eof 10 EOF))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]