Stephen Compall avatar 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)))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.