/**
* Reports a user-friendly error message for {@link MissingContextVariableException}.
*/
private void reportMissingContextVariableException(CpsStepContext context, MissingContextVariableException e) {
TaskListener tl;
try {
tl = context.get(TaskListener.class);
if (tl==null) return; // if we can't report an error, give up
} catch (IOException _) {
return;
} catch (InterruptedException _) {
return;
}
StringBuilder names = new StringBuilder();
for (StepDescriptor p : e.getProviders()) {
if (names.length()>0) names.append(',');
names.append(p.getFunctionName());
}
PrintStream logger = tl.getLogger();
logger.println(e.getMessage());
if (names.length()>0)
logger.println("Perhaps you forgot to surround the code with a step that provides this, such as: "+names);
}