Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

withMandatoryParameter supports a error message from the caller #177

Merged

Conversation

marcusholl
Copy link
Member

For some transport related steps it would be cool to have a message providing more details about what is going wrong.

throw new IllegalArgumentException("ERROR - NO VALUE AVAILABLE FOR ${key}")
if (paramValue == null) {
if(! errorMessage) errorMessage = "ERROR - NO VALUE AVAILABLE FOR ${key}"
throw new IllegalArgumentException(errorMessage)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to make use of the SimpleTemplateEngine:

import groovy.text.SimpleTemplateEngine

def getMandatoryProperty(key, defaultValue = null, errorMessage = "ERROR - NO VALUE AVAILABLE FOR ${key}"){
  [...]
  errorMessage = SimpleTemplateEngine.newInstance()
    .createTemplate(errorMessage)
    .make([key: key]).toString()

  throw new IllegalArgumentException(errorMessage)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CCFenner mmmhhhhhh ... Sounds like shooting on sparrows with cannons. Should we do that all the time we create a string containing a parameter? We have thousands of similar statements in the code using groovy strings for that. What is bad with the "good old" groovy string approach? Would make sense to use a template engine for big strings, like html templates where we have to replace variables with values when performance is an issue. But for a very simple and short string. What would be your general recommendation for using a TemplateEngine vs. using the groovy string pattern?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, the key is handed in from the outside anyway...

@marcusholl marcusholl merged commit 99c6012 into SAP:master Jul 4, 2018
@marcusholl marcusholl deleted the pr/customMessageForWithMandatoryParameter branch July 4, 2018 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants