FYI - Marco Baringer had these restart suggestions - this patch is  
against an old version of the code, but the idea is pretty clear if  
someone would like to integrate these in concert with the patch Leslie  
just sent out that enters the debugger on errors.

Cheers,
Ian

Begin forwarded message:
>
> just fyi i've been using two restarts around weblocks'
> handle-client-request and found it to be really helpful in dealing  
> with
> errors in the web interface.
>
> diff -r dd953902c06f src/control-flow/dialog.lisp
> --- a/src/control-flow/dialog.lisp    Thu Sep 04 19:56:43 2008 +0000
> +++ b/src/control-flow/dialog.lisp    Wed Sep 10 14:27:40 2008 +0200
> @@ -63,7 +63,9 @@
>   (if (ajax-request-p)
>       (prog2
>         (when (current-dialog)
> -         (error "Multiple dialogs not allowed."))
> +         (cerror "Ignore the current dialog."
> +                    "Multiple dialogs not allowed, currently have  
> ~S." (current-dialog))
> +            (setf (current-dialog) nil))
>         (call callee (lambda (new-callee)
>                        (setf (current-dialog) (make-dialog :title title
>                                                            :widget new-callee
> diff -r dd953902c06f src/request-handler.lisp
> --- a/src/request-handler.lisp        Thu Sep 04 19:56:43 2008 +0000
> +++ b/src/request-handler.lisp        Wed Sep 10 14:27:40 2008 +0200
> @@ -60,73 +60,84 @@
> (defmethod handle-client-request (app)
>   (let ((*current-webapp* app))
>     (declare (special *current-webapp*))
> -    (when (hunchentoot::mime-type (script-name))
> -      (setf (return-code) +http-not-found+)
> -      (throw 'handler-done nil))
> -    (when (null *session*)
> -      (when (get-request-action-name)
> -     (expired-action-handler app))
> -      (start-session)
> -      (setf (webapp-session-value 'last-request-uri) :none)
> -      (redirect (request-uri)))
> -    (when *maintain-last-session*
> -      (hunchentoot::with-lock (*maintain-last-session*)
> -     (setf *last-session* *session*)))
> -    (let ((*request-hook* (make-instance 'request-hooks)))
> -      (when (null (root-composite))
> -     (let ((root-composite (make-instance 'composite :name "root")))
> -       (when (weblocks-webapp-debug app)
> -         (initialize-debug-actions))
> -       (setf (root-composite) root-composite)
> -       (funcall (webapp-init-user-session) root-composite)
> -       (push 'update-dialog-on-request (request-hook :session :post- 
> action)))
> -     (when (cookie-in *session-cookie-name*)
> -       (redirect (remove-session-from-uri (request-uri)))))
> +    (restart-bind ((rehandle-request (lambda (&rest args)
> +                                       (declare (ignore args))
> +                                       (return-from handle-client- 
> request
> +                                         (handle-client-request  
> app)))
> +                     :report-function (lambda (stream)
> +                                        (format stream "Rehandle  
> request.")))
> +                   (abort-request (lambda (&rest args)
> +                                    (declare (ignore args))
> +                                    (return-from handle-client- 
> request "<h1>aborted</h1>"))
> +                     :report-function (lambda (stream)
> +                                        (format stream "Abort this  
> request."))))
> +      (when (hunchentoot::mime-type (script-name))
> +        (setf (return-code) +http-not-found+)
> +        (throw 'handler-done nil))
> +      (when (null *session*)
> +        (when (get-request-action-name)
> +          (expired-action-handler app))
> +        (start-session)
> +        (setf (webapp-session-value 'last-request-uri) :none)
> +        (redirect (request-uri)))
> +      (when *maintain-last-session*
> +        (hunchentoot::with-lock (*maintain-last-session*)
> +          (setf *last-session* *session*)))
> +      (let ((*request-hook* (make-instance 'request-hooks)))
> +        (when (null (root-composite))
> +          (let ((root-composite (make-instance 'composite :name  
> "root")))
> +            (when (weblocks-webapp-debug app)
> +              (initialize-debug-actions))
> +            (setf (root-composite) root-composite)
> +            (funcall (webapp-init-user-session) root-composite)
> +            (push 'update-dialog-on-request (request- 
> hook :session :post-action)))
> +          (when (cookie-in *session-cookie-name*)
> +            (redirect (remove-session-from-uri (request-uri)))))
>
> -      (let ((*weblocks-output-stream* (make-string-output-stream))
> -         (*uri-tokens* (tokenize-uri (request-uri)))
> -         (*current-navigation-url* "/") *dirty-widgets*
> -         *before-ajax-complete-scripts* *on-ajax-complete-scripts*
> -         *page-dependencies* *current-page-description*
> -         *uri-tokens-fully-consumed*)
> -     (declare (special *weblocks-output-stream* *current-navigation- 
> url* *dirty-widgets*
> -                       *on-ajax-complete-scripts* *uri-tokens* 
> *page-dependencies*
> -                       *current-page-description* 
> *uri-tokens-fully-consumed*))
> -     (when (pure-request-p)
> -       (throw 'handler-done (eval-action)))
> -     ;; a default dynamic-action hook function wraps get operations in  
> a transaction
> -     (eval-hook :pre-action)
> -     (with-dynamic-hooks (:dynamic-action)
> -       (eval-action))
> -     (eval-hook :post-action)
> -     (when (and (not (ajax-request-p))
> -                (find *action-string* (get-parameters)
> -                      :key #'car :test #'string-equal))
> -       (redirect (remove-action-from-uri (request-uri))))
> -     (eval-hook :pre-render)
> -     (with-dynamic-hooks (:dynamic-render)
> -       (if (ajax-request-p)
> -           (render-dirty-widgets)
> -           (progn
> -             ; we need to render widgets before the boilerplate HTML
> -             ; that wraps them in order to collect a list of script and
> -             ; stylesheet dependencies.
> -             (render-widget (root-composite))
> -             ; set page title if it isn't already set
> -             (when (and (null *current-page-description*)
> -                        (last *uri-tokens*))
> -               (setf *current-page-description*
> -                     (humanize-name (last-item *uri-tokens*))))
> -             ; render page will wrap the HTML already rendered to
> -             ; *weblocks-output-stream* with necessary boilerplate HTML
> -             (render-page app)
> -             ;; make sure all tokens were consumed
> -             (when (and (not *uri-tokens-fully-consumed*) *uri-tokens*)
> -               (page-not-found-handler app)))))
> -     (eval-hook :post-render)
> -     (unless (ajax-request-p)
> -       (setf (webapp-session-value 'last-request-uri) *uri-tokens*))
> -     (get-output-stream-string *weblocks-output-stream*)))))
> +        (let ((*weblocks-output-stream* (make-string-output-stream))
> +              (*uri-tokens* (tokenize-uri (request-uri)))
> +              (*current-navigation-url* "/") *dirty-widgets*
> +              *before-ajax-complete-scripts* *on-ajax-complete- 
> scripts*
> +              *page-dependencies* *current-page-description*
> +              *uri-tokens-fully-consumed*)
> +          (declare (special *weblocks-output-stream* *current- 
> navigation-url* *dirty-widgets*
> +                            *on-ajax-complete-scripts* *uri-tokens*  
> *page-dependencies*
> +                            *current-page-description* *uri-tokens- 
> fully-consumed*))
> +          (when (pure-request-p)
> +            (throw 'handler-done (eval-action)))
> +          ;; a default dynamic-action hook function wraps get  
> operations in a transaction
> +          (eval-hook :pre-action)
> +          (with-dynamic-hooks (:dynamic-action)
> +            (eval-action))
> +          (eval-hook :post-action)
> +          (when (and (not (ajax-request-p))
> +                     (find *action-string* (get-parameters)
> +                           :key #'car :test #'string-equal))
> +            (redirect (remove-action-from-uri (request-uri))))
> +          (eval-hook :pre-render)
> +          (with-dynamic-hooks (:dynamic-render)
> +            (if (ajax-request-p)
> +                (render-dirty-widgets)
> +                (progn
> +                                        ; we need to render widgets  
> before the boilerplate HTML
> +                                        ; that wraps them in order  
> to collect a list of script and
> +                                        ; stylesheet dependencies.
> +                  (render-widget (root-composite))
> +                                        ; set page title if it  
> isn't already set
> +                  (when (and (null *current-page-description*)
> +                             (last *uri-tokens*))
> +                    (setf *current-page-description*
> +                          (humanize-name (last-item *uri-tokens*))))
> +                                        ; render page will wrap the  
> HTML already rendered to
> +                                        ; *weblocks-output-stream*  
> with necessary boilerplate HTML
> +                  (render-page app)
> +                  ;; make sure all tokens were consumed
> +                  (when (and (not *uri-tokens-fully-consumed*) *uri- 
> tokens*)
> +                    (page-not-found-handler app)))))
> +          (eval-hook :post-render)
> +          (unless (ajax-request-p)
> +            (setf (webapp-session-value 'last-request-uri) *uri- 
> tokens*))
> +          (get-output-stream-string *weblocks-output-stream*))))))
>
> (defun remove-session-from-uri (uri)
>   "Removes the session info from a URI."
>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"weblocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/weblocks?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to