[Top][All Lists]

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

master 5fb9d6c5e72 5/5: Optionally continue on error in erc-auth-source-

From: F. Jason Park
Subject: master 5fb9d6c5e72 5/5: Optionally continue on error in erc-auth-source-search
Date: Sat, 23 Dec 2023 09:51:11 -0500 (EST)

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

    Optionally continue on error in erc-auth-source-search
    * doc/misc/erc.texi (auth-source): Add new "Troubleshooting"
    * lisp/erc/erc.el (erc-open): Initialize markers before determining
    session parameters.  Otherwise, functions that rely on
    `erc-inset-marker' being non-nil, like `erc-check-text-conversion',
    may fail during auth-source lookups.
    (erc-auth-source-search): When non-interactive, ask the user whether
    to continue connecting anyway.  (Bug#67978)
 doc/misc/erc.texi | 33 +++++++++++++++++++++++++++++----
 lisp/erc/erc.el   | 19 +++++++++++++++----
 2 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/doc/misc/erc.texi b/doc/misc/erc.texi
index 131e02555d1..61a4c9e1438 100644
--- a/doc/misc/erc.texi
+++ b/doc/misc/erc.texi
@@ -1674,6 +1674,7 @@ with the default backend, netrc, put a line like the 
following in your
 machine irc.example.net login mynick password sEcReT
 @end example
+@anchor{auth-source Server Password}
 @subsubheading Server Passwords
 When retrieving passwords to accompany the IRC @samp{PASS} command
 (@pxref{password parameter}), ERC asks auth-source to match the
@@ -1723,10 +1724,7 @@ auth-source experience.  (@xref{SASL}.)
 @subsubheading Default query behavior
 When preparing entries for your backend, it may help to get a feel for
 how ERC and its modules conduct searches, especially when exploring a
-new context, such as channel keys.  (Hint: in such situations, try
-temporarily setting the variable @code{auth-source-debug} to @code{t}
-and checking @file{*Messages*} periodically for insights into how
-auth-source is operating.)  Overall, though, ERC tries to be
+new context, such as channel keys.  Overall, though, ERC tries to be
 consistent in performing queries across various authentication
 contexts.  Here's what to expect with respect to the @samp{host}
 field, which, by default, most heavily influences the fate of a query:
@@ -1810,6 +1808,33 @@ required by certain channels you join.  When modifying a 
 @samp{user} field (for example, @samp{login "#fsf"}, in netrc's case).
 The actual key goes in the @samp{password} (or @samp{secret}) field.
+@anchor{auth-source Troubleshooting}
+@subheading Troubleshooting
+By default, ERC queries @code{auth-source} for channel keys and server
+passwords (@pxref{auth-source Server Password}), as well as other,
+module-specific credentials.  In general, if you're having trouble
+calling @code{auth-source-search} in a custom query function, like
+@code{erc-auth-source-server-function}, try temporarily setting the
+variable @code{auth-source-debug} to @code{t} and checking
+@file{*Messages*} periodically for insights into how
+@code{auth-source} is operating.
+If you're using a @acronym{GPG}-encrypted file and find that
+customizing one of the function-valued query options doesn't solve
+your problem, explore options @code{epg-pinentry-mode} and
+@code{epg-debug} in the @code{epg} Custom group (@pxref{GnuPG
+Pinentry,,, epa, EasyPG Assistant}).  Additionally, keep an eye out
+for an @file{*Error*} buffer, which may contain more specific clues
+about your situation.  If you use the libsecrets integration
+(@pxref{Secret Service API,,, auth, Emacs auth-source}) with something
+like GNOME Keyring, you may need to check the ``remember'' box in the
+passphrase popup dialog to avoid being prompted for confirmation every
+time you run ERC.  If it doesn't work at first, try logging out.  And
+when in doubt, try using the Emacs command @code{secrets-show-secrets}
+to browse the @samp{Login} keyring.  There should be a
+@samp{GnuPG/stored-by} entry with a value of @samp{GnuPG Pinentry} or
 @node display-buffer
 @subsection display-buffer
 @cindex display-buffer
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 6eee8bcae92..ab9c769cbbf 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -2542,8 +2542,8 @@ Returns the buffer for the given server or channel."
           (when erc-log-p
             (get-buffer-create (concat "*ERC-DEBUG: " server "*"))))
-    (erc-determine-parameters server port nick full-name user passwd)
     (erc--initialize-markers old-point continued-session)
+    (erc-determine-parameters server port nick full-name user passwd)
     (save-excursion (run-mode-hooks)
                     (dolist (mod (car delayed-modules)) (funcall mod +1))
                     (dolist (var (cdr delayed-modules)) (set var nil)))
@@ -4400,11 +4400,22 @@ the one with host foo would win."
       (plist-get (car sorted) :secret))))
 (defun erc-auth-source-search (&rest plist)
-  "Call `auth-source-search', possibly with keyword params in PLIST."
+  "Call `auth-source-search', possibly with keyword params in PLIST.
+If the search signals an error before returning, `warn' the user
+and ask whether to continue connecting anyway."
   ;; These exist as separate helpers in case folks should find them
   ;; useful.  If that's you, please request that they be exported.
-  (apply #'erc--auth-source-search
-         (apply #'erc--auth-source-determine-params-merge plist)))
+  (condition-case err
+      (apply #'erc--auth-source-search
+             (apply #'erc--auth-source-determine-params-merge plist))
+    (error
+     (erc--lwarn '(erc auth-source) :error
+                 "Problem querying `auth-source': %S. See %S for more."
+                 (error-message-string err)
+                 '(info "(erc) auth-source Troubleshooting"))
+     (when (or noninteractive
+               (not (y-or-n-p "Ignore auth-source error and continue? ")))
+       (signal (car err) (cdr err))))))
 (defun erc-server-join-channel (server channel &optional secret)
   "Join CHANNEL, optionally with SECRET.

reply via email to

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