Stephen Compall committed c196b16

Define style-warning types for online webapp programming advice

Comments (0)

Files changed (1)


 		 (redirect (make-webapp-uri "/")))
+;;; Further aid in debugging by reporting potential problems
+(defun style-warn (condition &rest warn-args)
+  "A variant of `warn' that doesn't guarantee evaluation of its
+  (apply #'warn condition warn-args))
+(define-compiler-macro style-warn (condition &rest warn-args)
+  `(when (or (not (boundp '*current-webapp*))
+	     (weblocks-webapp-debug (current-webapp)))
+     (warn ,condition . ,warn-args)))
+(define-condition webapp-style-warning (style-warning)
+  ()
+  (:documentation "Signalled by Weblocks when detecting unwise
+behavior on the part of webapps."))
+(define-condition non-idempotent-rendering (webapp-style-warning)
+  ((change-made :initarg :change-made :reader change-made-during-rendering
+		:documentation "A description of the change that
+		should be moved to action handling."))
+  (:report report-non-idempotent-rendering)
+  (:documentation "Signalled in common cases where code that alters
+the webapp state appears in a rendering process."))
+(defun report-non-idempotent-rendering (c stream)
+  "Describe a condition where code appears in rendering that should be
+in the action handler."
+  (format stream "During the rendering phase, ~A, which should ~
+		  typically be done only during action handling"
+	  (change-made-during-rendering c)))