/[meta-cvs]/meta-cvs/F-9AB435A23565E6385CE7F4F347D7A205
ViewVC logotype

Contents of /meta-cvs/F-9AB435A23565E6385CE7F4F347D7A205

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (show annotations)
Thu Apr 24 04:14:41 2003 UTC (10 years, 11 months ago) by kaz
Branch: MAIN
Changes since 1.13: +8 -21 lines
Merging from mcvs-1-0-branch.

Improved error handling again in a flash of sanity. The whole
idea of ``bail'' as a restart is gone. All code which must perform
some complex cleanup action does so as part of normal unwinding.
And so termination becomes safe.

* code/update.lisp (mcvs-update): Change bail restart to continue.

* code/mcvs-main.lisp (*global-options*): Remove "error-bail".
(*usage*): Remove description of --error-bail.
(mcvs-execute): Bind *mcvs-error-treatment* to :terminate rather
than :bail if controlling TTY cannot be opened.

* code/move.lisp (mcvs-move): Change "Undoing move" error message
to "Undoing changes to map".

* code/add.lisp (mcvs-add): Get rid of bail restart; move cleanup
code into unwind-protect block.

* code/error.lisp (*mcvs-error-treatment*): Touch up docstring.
(mcvs-error-handler): Remove anything having to do with :bail.
Change description of `T' command to suggest that it is safe.

* code/options.lisp (filter-mcvs-options): Remove handling of
"error-bail" option.

* code/mapping.lisp (mapping-update): Get rid of outermost
restart-case, which had just a bail restart. Replace it with
unwind-protect block which does exactly the same restoration.
1 ;;; This source file is part of the Meta-CVS program,
2 ;;; which is distributed under the GNU license.
3 ;;; Copyright 2002 Kaz Kylheku
4
5 (require "chatter")
6 (require "find-bind")
7 (require "mcvs-package")
8 (provide "error")
9
10 (in-package "META-CVS")
11
12 (defvar *mcvs-error-treatment* :interactive
13 "This variable is used by the top level error handler set up in mcvs-execute to
14 decide on what to do with a restartable error condition. If no restarts are
15 available, then this variable is ignored; the handler will print the error
16 message and terminate the program. If the error is restartable, then this
17 variable is examined. A value of :interactive indicates that a menu of options
18 should be presented to a user, who can choose to terminate the program,
19 or invoke one of the available restarts. A value of :continue means
20 to emit a warning message and then invoke the a continue restart if
21 one is available. If restarts are available, but not ones that can
22 be automatically selected by the handler, then it will terminate the
23 program. A value of :terminate means to terminate on error, restartable
24 or not. A value of :decline means to return normally handling the error.")
25
26 (defvar *mcvs-errors-occured-p* nil)
27
28 (defvar *interactive-error-io* nil)
29
30 (defun mcvs-terminate (condition)
31 (format *error-output* "mcvs: ~a~%" condition)
32 (throw 'mcvs-terminate t))
33
34 (defun mcvs-error-handler (condition)
35 (let ((*print-escape* nil))
36 (setf *mcvs-errors-occured-p* t)
37 (find-bind (:key #'restart-name)
38 (others (continue 'continue)
39 (info 'info)
40 (retry 'retry))
41 (compute-restarts)
42 (ecase *mcvs-error-treatment*
43 ((:interactive)
44 (unless *interactive-error-io*
45 (return-from mcvs-error-handler nil))
46 (when (null (compute-restarts))
47 (mcvs-terminate condition))
48 (let* (command-list
49 (menu (with-output-to-string (stream)
50 (format stream "~%The following error has occured:~%~%")
51 (format stream " ~a~%~%" condition)
52 (format stream "You have these alternatives:~%~%")
53 (format stream " ?) Re-print this menu.~%" continue)
54 (when info
55 (format stream " I) (Info) ~a~%" info)
56 (push (list "I" #'(lambda ()
57 (invoke-restart info)))
58 command-list))
59 (when continue
60 (format stream " C) (Continue) ~a~%" continue)
61 (format stream " A) Auto-continue all continuable errors.~%")
62 (push (list "C" #'(lambda ()
63 (invoke-restart continue)))
64 command-list)
65 (push (list "A" #'(lambda ()
66 (setf *mcvs-error-treatment*
67 :continue)
68 (invoke-restart continue)))
69 command-list))
70 (when retry
71 (format stream " R) (Retry) ~a~%" retry)
72 (push (list "R" #'(lambda ()
73 (invoke-restart retry)))
74 command-list))
75 (format stream " T) Recover, clean-up and terminate.~%")
76 (push (list "T" #'(lambda ()
77 (throw 'mcvs-terminate t)))
78 command-list)
79 (when others
80 (format stream "~%These special alternatives are also available:~%~%")
81 (let ((counter 0))
82 (dolist (restart others)
83 (format stream " ~a) ~a~%" (incf counter) restart)
84 (push (list (format nil "~a" counter)
85 (let ((restart restart))
86 #'(lambda ()
87 (invoke-restart restart))))
88 command-list))))
89 (terpri stream))))
90 (write-string menu *interactive-error-io*)
91 (loop
92 (write-string ">" *interactive-error-io*)
93 (let* ((line (read-line *interactive-error-io*))
94 (command (find line command-list
95 :key #'first
96 :test #'string-equal)))
97 (cond
98 ((string= line "?")
99 (write-string menu *interactive-error-io*))
100 (command
101 (funcall (second command)))
102 (t (format *interactive-error-io* "What?~%")))))))
103 ((:continue)
104 (when continue
105 (chatter-terse "Auto-continuing error:~%")
106 (chatter-terse " ~a~%" condition)
107 (invoke-restart continue))
108 (mcvs-terminate condition))
109 ((:terminate)
110 (mcvs-terminate condition))
111 ((:decline)
112 (return-from mcvs-error-handler nil))))))

  ViewVC Help
Powered by ViewVC 1.1.5