Warn users in dev mode when they set a RequestVar but don't use it
Updated 2 years, 3 months ago
| Derek Chen-Becker | Reviewers | ||
| 138 | dchenbecker, dpp, marius, charles, heiko, joni, atsuhiko, jorge, naftoli, kris, indrajit, alexb | ||
| None | LiftWeb-archive | ||
While Marius and I were discussing the lazy-load functionality, we realized that it would be nice to warn people when they're setting a RequestVar and then never read it in the same request. I also took the opportunity to refactor some "magic strings" into a constants object.
On my local test app.
Posted 2 years, 3 months ago (October 27th, 2009, 4:42 p.m.)
This is going to generate a lot of spurious messages. A fair amount of Lift's internals are built on RequestVars that self-initialize based on the current request.
Posted 2 years, 3 months ago (October 27th, 2009, 9 p.m.)
There are different styles of dealing with accessing RequestVars before they are set. For example, if it's a logic error to access a RequestVar before it's set, my style would be:
object MyVar extends RequestVar[String](throw new NullPointerException("Tried to access MyVar before setting it"))
I also understand that your approach (logging access before set by default) is reasonable.
So, please add the following to allow for supporting my approach (which is not to log, but to make explicit when it's a logic error to access before setting):
- A LiftRule (structured like allowParallelSnippets) that allows the disabling of the log messages. You can log by default, but I'd like a way to accommodate my style with a simple one-liner in Boot.
- Allow opting out of the logging on a RequestVar by RequestVar basis. This allows one to have a particular RequestVar that's okay to access before setting, but allow for the logging of everyone else
Review request changed
Updated 2 years, 3 months ago (October 27th, 2009, 11:04 p.m.)
-
- added Diff r2
Fixed a bug where the default initializer caused a log statement to be output.
I'm ok with it.
Review request changed
Updated 2 years, 3 months ago (October 28th, 2009, 2:09 p.m.)
-
- added Diff r3
Added global and per-RV opt-out.
