[jira] [Created] (VELOCITY-987) Directive to fail execution of the current template with an error message

"Arend v. Reinersdorff (Jira)" <[email protected]>
Newsgroups gmane.comp.jakarta.velocity.devel
Message-ID <[email protected]>
Arend v. Reinersdorff created VELOCITY-987:
----------------------------------------------

             Summary: Directive to fail execution of the current template with an error message
                 Key: VELOCITY-987
                 URL: https://issues.apache.org/jira/browse/VELOCITY-987
             Project: Velocity
          Issue Type: New Feature
            Reporter: Arend v. Reinersdorff


My current use case is generating a Dockerfile and setting the base image according to a Java version parameter. Accepted values for Java versions are limited (17, 11, 8). Problem was when 21 was added as a new Java version, the if-block was not updated. Template generation succeeded using a fallback image and an error appeared later.

If the fallback could have failed the template generation, the error would have been discovered sooner.

*Requirements*
 * Directive to fail the template generation
 * Ability to add an error message
 * Error should lead to the place of failure (template file, line number)

*Example usage*
{code:java}
#if (${javaVersion} == '21')
    FROM icr.io/appcafe/open-liberty:full-java21-openj9-ubi-minimal
#elseif (${javaVersion} == '17')
    FROM icr.io/appcafe/open-liberty:full-java17-openj9-ubi
#else
    #fail("Unsupported Java version: ${javaVersion}")
#end{code}
Error  message might loook like this:

Template execution failed for example.vm line 6: Unsupported Java version: 11

*Difference to stop*

I am aware of the #stop directive. But as it doesn't fail the template generation. So it is not visible that an error occured.

*See also*

https://stackoverflow.com/questions/46587599/how-to-fail-velocity-template-processing-with-tracable-message



--
This message was sent by Atlassian Jira
(v8.20.10#820010)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.