Commit 525c5c77 authored by Michael Albinus's avatar Michael Albinus
Browse files

Improve error messages. (Bug#14808)

* net/tramp.el (tramp-current-connection): New defvar, moved from
tramp-sh.el.
(tramp-message-show-progress-reporter-message): Removed, not
needed anymore.
(tramp-error-with-buffer): Show message in minibuffer.  Discard
input before waiting.  Reset connection timestamp.
(with-tramp-progress-reporter): Improve messages.
(tramp-process-actions): Use progress reporter.  Delete process in
case of error.  Improve messages.

* net/tramp-sh.el (tramp-barf-if-no-shell-prompt): Use
condition-case.  Call `tramp-error-with-buffer' with vector and buffer.
(tramp-current-connection): Removed.
(tramp-maybe-open-connection): The car of
`tramp-current-connection' are the first 3 slots of the vector.
parent c7a4d368
2013-07-10 Michael Albinus <michael.albinus@gmx.de>
Improve error messages. (Bug#14808)
* net/tramp.el (tramp-current-connection): New defvar, moved from
tramp-sh.el.
(tramp-message-show-progress-reporter-message): Removed, not
needed anymore.
(tramp-error-with-buffer): Show message in minibuffer. Discard
input before waiting. Reset connection timestamp.
(with-tramp-progress-reporter): Improve messages.
(tramp-process-actions): Use progress reporter. Delete process in
case of error. Improve messages.
* net/tramp-sh.el (tramp-barf-if-no-shell-prompt): Use
condition-case. Call `tramp-error-with-buffer' with vector and buffer.
(tramp-current-connection): Removed.
(tramp-maybe-open-connection): The car of
`tramp-current-connection' are the first 3 slots of the vector.
2013-07-10 Teodor Zlatanov <tzz@lifelogs.com> 2013-07-10 Teodor Zlatanov <tzz@lifelogs.com>
* progmodes/cfengine.el (cfengine3-indent-line): Do not indent * progmodes/cfengine.el (cfengine3-indent-line): Do not indent
......
...@@ -3752,12 +3752,16 @@ file exists and nonzero exit status otherwise." ...@@ -3752,12 +3752,16 @@ file exists and nonzero exit status otherwise."
"Wait for shell prompt and barf if none appears. "Wait for shell prompt and barf if none appears.
Looks at process PROC to see if a shell prompt appears in TIMEOUT Looks at process PROC to see if a shell prompt appears in TIMEOUT
seconds. If not, it produces an error message with the given ERROR-ARGS." seconds. If not, it produces an error message with the given ERROR-ARGS."
(unless (let ((vec (tramp-get-connection-property proc "vector" nil)))
(tramp-wait-for-regexp (condition-case err
proc timeout (tramp-wait-for-regexp
(format proc timeout
"\\(%s\\|%s\\)\\'" shell-prompt-pattern tramp-shell-prompt-pattern)) (format
(apply 'tramp-error-with-buffer nil proc 'file-error error-args))) "\\(%s\\|%s\\)\\'" shell-prompt-pattern tramp-shell-prompt-pattern))
(error
(delete-process proc)
(apply 'tramp-error-with-buffer
(tramp-get-connection-buffer vec) vec 'file-error error-args)))))
(defun tramp-open-connection-setup-interactive-shell (proc vec) (defun tramp-open-connection-setup-interactive-shell (proc vec)
"Set up an interactive shell. "Set up an interactive shell.
...@@ -4332,9 +4336,6 @@ Gateway hops are already opened." ...@@ -4332,9 +4336,6 @@ Gateway hops are already opened."
;; Result. ;; Result.
target-alist)) target-alist))
(defvar tramp-current-connection nil
"Last connection timestamp.")
(defun tramp-maybe-open-connection (vec) (defun tramp-maybe-open-connection (vec)
"Maybe open a connection VEC. "Maybe open a connection VEC.
Does not do anything if a connection is already open, but re-opens the Does not do anything if a connection is already open, but re-opens the
...@@ -4348,7 +4349,7 @@ connection if a previous connection has died for some reason." ...@@ -4348,7 +4349,7 @@ connection if a previous connection has died for some reason."
;; If Tramp opens the same connection within a short time frame, ;; If Tramp opens the same connection within a short time frame,
;; there is a problem. We shall signal this. ;; there is a problem. We shall signal this.
(unless (or (and p (processp p) (memq (process-status p) '(run open))) (unless (or (and p (processp p) (memq (process-status p) '(run open)))
(not (equal (butlast (append vec nil)) (not (equal (butlast (append vec nil) 2)
(car tramp-current-connection))) (car tramp-current-connection)))
(> (tramp-time-diff (> (tramp-time-diff
(current-time) (cdr tramp-current-connection)) (current-time) (cdr tramp-current-connection))
...@@ -4433,7 +4434,7 @@ connection if a previous connection has died for some reason." ...@@ -4433,7 +4434,7 @@ connection if a previous connection has died for some reason."
(set-process-sentinel p 'tramp-process-sentinel) (set-process-sentinel p 'tramp-process-sentinel)
(tramp-compat-set-process-query-on-exit-flag p nil) (tramp-compat-set-process-query-on-exit-flag p nil)
(setq tramp-current-connection (setq tramp-current-connection
(cons (butlast (append vec nil)) (current-time)) (cons (butlast (append vec nil) 2) (current-time))
tramp-current-host (system-name)) tramp-current-host (system-name))
(tramp-message (tramp-message
...@@ -4442,7 +4443,7 @@ connection if a previous connection has died for some reason." ...@@ -4442,7 +4443,7 @@ connection if a previous connection has died for some reason."
;; Check whether process is alive. ;; Check whether process is alive.
(tramp-barf-if-no-shell-prompt (tramp-barf-if-no-shell-prompt
p 60 p 60
"Couldn't find local shell prompt %s" tramp-encoding-shell) "Couldn't find local shell prompt for %s" tramp-encoding-shell)
;; Now do all the connections as specified. ;; Now do all the connections as specified.
(while target-alist (while target-alist
......
...@@ -1071,6 +1071,9 @@ means to use always cached values for the directory contents." ...@@ -1071,6 +1071,9 @@ means to use always cached values for the directory contents."
(defvar tramp-current-host nil (defvar tramp-current-host nil
"Remote host for this *tramp* buffer.") "Remote host for this *tramp* buffer.")
(defvar tramp-current-connection nil
"Last connection timestamp.")
;;;###autoload ;;;###autoload
(defconst tramp-completion-file-name-handler-alist (defconst tramp-completion-file-name-handler-alist
'((file-name-all-completions . tramp-completion-handle-file-name-all-completions) '((file-name-all-completions . tramp-completion-handle-file-name-all-completions)
...@@ -1464,10 +1467,6 @@ ARGS to actually emit the message (if applicable)." ...@@ -1464,10 +1467,6 @@ ARGS to actually emit the message (if applicable)."
This variable is used to disable messages from `tramp-error'. This variable is used to disable messages from `tramp-error'.
The messages are visible anyway, because an error is raised.") The messages are visible anyway, because an error is raised.")
(defvar tramp-message-show-progress-reporter-message t
"Show Tramp progress reporter message in the minibuffer.
This variable is used to disable recursive progress reporter messages.")
(defsubst tramp-message (vec-or-proc level fmt-string &rest args) (defsubst tramp-message (vec-or-proc level fmt-string &rest args)
"Emit a message depending on verbosity level. "Emit a message depending on verbosity level.
VEC-OR-PROC identifies the Tramp buffer to use. It can be either a VEC-OR-PROC identifies the Tramp buffer to use. It can be either a
...@@ -1547,12 +1546,13 @@ an input event arrives. The other arguments are passed to `tramp-error'." ...@@ -1547,12 +1546,13 @@ an input event arrives. The other arguments are passed to `tramp-error'."
(or (and (bufferp buffer) buffer) (or (and (bufferp buffer) buffer)
(and (processp vec-or-proc) (process-buffer vec-or-proc)) (and (processp vec-or-proc) (process-buffer vec-or-proc))
(tramp-get-connection-buffer vec-or-proc))) (tramp-get-connection-buffer vec-or-proc)))
(when (string-equal fmt-string "Process died") ;; `tramp-error' does not show messages. So we must do it ourselves.
(message (message fmt-string args)
"%s\n %s" (discard-input)
"Tramp failed to connect. If this happens repeatedly, try" (sit-for 30)))
"`M-x tramp-cleanup-this-connection'")) ;; Reset timestamp. It would be wrong after waiting for a while.
(sit-for 30)))))) (when tramp-current-connection
(setcdr tramp-current-connection (current-time))))))
(defmacro with-parsed-tramp-file-name (filename var &rest body) (defmacro with-parsed-tramp-file-name (filename var &rest body)
"Parse a Tramp filename and make components available in the body. "Parse a Tramp filename and make components available in the body.
...@@ -1604,23 +1604,27 @@ progress reporter." ...@@ -1604,23 +1604,27 @@ progress reporter."
(tramp-message ,vec ,level "%s..." ,message) (tramp-message ,vec ,level "%s..." ,message)
;; We start a pulsing progress reporter after 3 seconds. Feature ;; We start a pulsing progress reporter after 3 seconds. Feature
;; introduced in Emacs 24.1. ;; introduced in Emacs 24.1.
(when (and tramp-message-show-progress-reporter-message (when (and tramp-message-show-message
tramp-message-show-message
;; Display only when there is a minimum level. ;; Display only when there is a minimum level.
(<= ,level (min tramp-verbose 3))) (<= ,level (min tramp-verbose 3)))
(ignore-errors (ignore-errors
(setq pr (tramp-compat-funcall 'make-progress-reporter ,message) (setq pr (tramp-compat-funcall 'make-progress-reporter ,message)
tm (when pr tm (when pr
(run-at-time 3 0.1 'tramp-progress-reporter-update pr))))) (run-at-time 3 0.1 'tramp-progress-reporter-update pr)))))
(unwind-protect (condition-case err
;; Execute the body. Suppress concurrent progress reporter (unwind-protect
;; messages. ;; Execute the body.
(let ((tramp-message-show-progress-reporter-message (progn ,@body)
(and tramp-message-show-progress-reporter-message (not tm)))) ;; Stop progress reporter.
,@body) (if tm (tramp-compat-funcall 'cancel-timer tm)))
;; Stop progress reporter.
(if tm (tramp-compat-funcall 'cancel-timer tm)) ;; Error handling.
(tramp-message ,vec ,level "%s...done" ,message)))) ((error quit)
(tramp-message ,vec ,level "%s...failed" ,message)
(signal (car err) (cdr err))))
;; Exit.
(tramp-message ,vec ,level "%s...done" ,message)))
(tramp-compat-font-lock-add-keywords (tramp-compat-font-lock-add-keywords
'emacs-lisp-mode '("\\<with-tramp-progress-reporter\\>")) 'emacs-lisp-mode '("\\<with-tramp-progress-reporter\\>"))
...@@ -3393,39 +3397,47 @@ The terminal type can be configured with `tramp-terminal-type'." ...@@ -3393,39 +3397,47 @@ The terminal type can be configured with `tramp-terminal-type'."
PROC and VEC indicate the remote connection to be used. POS, if PROC and VEC indicate the remote connection to be used. POS, if
set, is the starting point of the region to be deleted in the set, is the starting point of the region to be deleted in the
connection buffer." connection buffer."
;; Preserve message for `progress-reporter'. ;; Enable `auth-source' and `password-cache'. We must use
(tramp-compat-with-temp-message "" ;; tramp-current-* variables in case we have several hops.
;; Enable `auth-source' and `password-cache'. We must use (tramp-set-connection-property
;; tramp-current-* variables in case we have several hops. (tramp-dissect-file-name
(tramp-set-connection-property (tramp-make-tramp-file-name
(tramp-dissect-file-name tramp-current-method tramp-current-user tramp-current-host ""))
(tramp-make-tramp-file-name "first-password-request" t)
tramp-current-method tramp-current-user tramp-current-host "")) (save-restriction
"first-password-request" t) (with-tramp-progress-reporter
(save-restriction proc 3 "Waiting for prompts from remote shell"
(let (exit) (let (exit)
(while (not exit) (if timeout
(tramp-message proc 3 "Waiting for prompts from remote shell") (with-timeout (timeout (setq exit 'timeout))
(setq exit (while (not exit)
(catch 'tramp-action (setq exit
(if timeout (catch 'tramp-action
(with-timeout (timeout) (tramp-process-one-action proc vec actions)))))
(tramp-process-one-action proc vec actions)) (while (not exit)
(setq exit
(catch 'tramp-action
(tramp-process-one-action proc vec actions))))) (tramp-process-one-action proc vec actions)))))
(with-current-buffer (tramp-get-connection-buffer vec) (with-current-buffer (tramp-get-connection-buffer vec)
(widen) (widen)
(tramp-message vec 6 "\n%s" (buffer-string))) (tramp-message vec 6 "\n%s" (buffer-string)))
(unless (eq exit 'ok) (unless (eq exit 'ok)
(tramp-clear-passwd vec) (tramp-clear-passwd vec)
(delete-process proc)
(tramp-error-with-buffer (tramp-error-with-buffer
nil vec 'file-error (tramp-get-connection-buffer vec) vec 'file-error
(cond (cond
((eq exit 'permission-denied) "Permission denied") ((eq exit 'permission-denied) "Permission denied")
((eq exit 'process-died) "Process died") ((eq exit 'process-died)
(t "Login failed")))) (concat
(when (numberp pos) "Tramp failed to connect. If this happens repeatedly, try\n"
(with-current-buffer (tramp-get-connection-buffer vec) " `M-x tramp-cleanup-this-connection'"))
(let (buffer-read-only) (delete-region pos (point))))))))) ((eq exit 'timeout)
"Timeout reached. Check the buffer for the error reason")
(t "Login failed")))))
(when (numberp pos)
(with-current-buffer (tramp-get-connection-buffer vec)
(let (buffer-read-only) (delete-region pos (point))))))))
:;; Utility functions: :;; Utility functions:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment