Having:
- Velocity template or macro
- some object
How to validate the object (#if) and fail (stop further processing) in a way that is easily tracable to the place of failure (like throwing exception in Java).
I am looking for something like this:
#if ( ! $context.treasureMap.containsKey('gold'))
#fail('no golden treasure here')
#end
Background
I am writing a maven site page. The velocity context is injected by maven and contains POM information. I want to test existence of some information from effective pom. When the information is not available, I want to fail.
Requirements
- fail Velocity processing > fail site generation > fail maven build.
- error message should lead to the place of failure so the site should be fixed
- preferably no configuration (no extensions, just constructs/tools contained in plain Velocity)
Tried
- Strict Reference Mode
Unwanted configuration, do not want to fail on every occasion. #evaluate('#end')
aka syntax error
(Chose#end
as most descriptive to my intent) Basically what I want. Fails the processing and maven build but the error message does not lead back to failure location:ParseException: Encountered "#end" at line 1, column 1.
.