>From 5478db49a2949d2835b79ea460eac11853b190c3 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Mon, 12 Dec 2022 23:58:03 -0800 Subject: [PATCH 4/5] Set erc-network to a "given" ID instead of failing * lisp/erc/erc-networks.el (erc-networks--determine): Return the so-called "given" ID from a non-nil `:id' keyword arg passed to `erc' or `erc-tls'. (erc-networks--set-name): Tell the user about falling back to a given ID when the network can't be determined. Destroy the connection when network cannot be determined. (Bug#59976.) (erc-networks--ensure-announced): Include the fallback announced name in the error message. * test/lisp/erc/erc-networks-tests.el (erc-networks--set-name): Add dummy server process to test. --- lisp/erc/erc-networks.el | 34 +++++++++++++++++++---------- test/lisp/erc/erc-networks-tests.el | 2 ++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/lisp/erc/erc-networks.el b/lisp/erc/erc-networks.el index 19a7ab8643..51ba54f45c 100644 --- a/lisp/erc/erc-networks.el +++ b/lisp/erc/erc-networks.el @@ -60,6 +60,7 @@ erc-session-server (declare-function erc-buffer-filter "erc" (predicate &optional proc)) (declare-function erc-current-nick "erc" nil) (declare-function erc-display-error-notice "erc" (parsed string)) +(declare-function erc-display-message "erc" (parsed type buffer msg &rest args)) (declare-function erc-error "erc" (&rest args)) (declare-function erc-get-buffer "erc" (target &optional proc)) (declare-function erc-server-buffer "erc" nil) @@ -1260,21 +1261,31 @@ erc-networks--determine return name) (and-let* ((vanity (erc--get-isupport-entry 'NETWORK 'single)) ((intern vanity)))) + (erc-networks--id-given erc-networks--id) erc-networks--name-missing-sentinel)) -(defun erc-networks--set-name (_proc parsed) +(defun erc-networks--set-name (proc parsed) "Set `erc-network' to the value returned by `erc-networks--determine'. -Signal an error when the network cannot be determined." +Signal an error when the network cannot be determined after first +shutting down the connection." ;; Always update (possibly clobber) current value, if any. (let ((name (erc-networks--determine))) + (when (eq name (erc-networks--id-given erc-networks--id)) + (let ((m (format "Couldn't determine network. Using given ID `%s'." + name))) + (erc-display-message parsed 'notice nil m))) (when (eq name erc-networks--name-missing-sentinel) - ;; This can happen theoretically, e.g., if you're editing some - ;; settings interactively on a proxy service that impersonates IRC - ;; but aren't being proxied through to a real network. The + ;; This can happen theoretically, e.g., when adjusting settings + ;; on a proxy service that partially impersonates IRC but isn't + ;; currently conveying anything through to a real network. The ;; service may send a 422 but no NETWORK param (or *any* 005s). - (let ((m (concat "Failed to determine network. Please set entry for " - erc-server-announced-name " in `erc-networks-alist'."))) + (let ((m (concat "Failed to determine network. Please set entry for \"" + erc-server-announced-name "\" in `erc-networks-alist'" + " or consider calling `erc-tls' with the keyword `:id'." + " See Info:\"(erc) Network Identifier\" for more."))) (erc-display-error-notice parsed m) + (run-hook-with-args 'erc-quit-hook proc) + (delete-process proc) (erc-error "Failed to determine network"))) ; beep (setq erc-network name)) nil) @@ -1287,11 +1298,12 @@ erc-networks--ensure-announced Copy source (prefix) from MOTD-ish message as a last resort." ;; The 004 handler never ran; see 2004-03-10 Diane Murray in change log (unless erc-server-announced-name - (erc-display-error-notice parsed "Failed to determine server name.") + (setq erc-server-announced-name (erc-response.sender parsed)) (erc-display-error-notice - parsed (concat "If this was unexpected, consider reporting it via " - (substitute-command-keys "\\[erc-bug]") ".")) - (setq erc-server-announced-name (erc-response.sender parsed))) + parsed (concat "Failed to determine server name. Using \"" + erc-server-announced-name "\" instead." + " If this was unexpected, consider reporting it via " + (substitute-command-keys "\\[erc-bug]") "."))) nil) (defun erc-unset-network-name (_nick _ip _reason) diff --git a/test/lisp/erc/erc-networks-tests.el b/test/lisp/erc/erc-networks-tests.el index fc12bf7ce3..02fc57d4e6 100644 --- a/test/lisp/erc/erc-networks-tests.el +++ b/test/lisp/erc/erc-networks-tests.el @@ -1171,6 +1171,8 @@ erc-networks--set-name (let (erc-server-announced-name (erc--isupport-params (make-hash-table)) erc-network + erc-quit-hook + (erc-server-process (erc-networks-tests--create-live-proc)) calls) (erc-mode) -- 2.38.1