protected InvalidReferenceException newNullPropertyException( String propertyName, TemplateModel tm, Environment env) { if (env.getFastInvalidReferenceExceptions()) { return InvalidReferenceException.FAST_INSTANCE; } else { return new InvalidReferenceException( new _ErrorDescriptionBuilder( "The exteneded hash (of class ", tm.getClass().getName(), ") has returned null for its \"", propertyName, "\" property. This is maybe a bug. The extended hash was returned by this expression:") .blame(target), env, this); } }
final _ErrorDescriptionBuilder errDescBuilder = new _ErrorDescriptionBuilder("The following has evaluated to null or missing:").blame(blamed); if (endsWithDollarVariable(blamed)) { errDescBuilder.tips(TIP_NO_DOLLAR, TIP); } else if (blamed instanceof Dot) { errDescBuilder.tip(TIP); return new InvalidReferenceException(errDescBuilder, env, blamed); } else { return new InvalidReferenceException(env);
void assertNonNull(TemplateModel model, Environment env) throws InvalidReferenceException { if (model == null) throw InvalidReferenceException.getInstance(this, env); }
} else { if (exp != null) { throw InvalidReferenceException.getInstance(exp, env); } else { throw new InvalidReferenceException( "Null/missing value (no more informatoin avilable)", env);
private String executeInternal(String templateName, Object value) { Preconditions.checkNotNull(templateName, "templateName cannot be null."); Preconditions.checkNotNull(value, "values cannot be null."); Template template; try { template = this.configuration.getTemplate(templateName); } catch (IOException ex) { throw new DataException( String.format("Exception thrown while loading template '%s'", templateName), ex ); } try (StringWriter writer = new StringWriter()) { template.process(value, writer); return writer.toString(); } catch (IOException e) { throw new ConnectException("Exception while processing template", e); } catch (InvalidReferenceException e) { throw new DataException( String.format( "Exception thrown while processing template. Offending expression '%s'", e.getBlamedExpressionString() ), e); } catch (TemplateException e) { throw new ConnectException("Exception while processing template", e); } }
msgBuf.append("?").append(req.getQueryString()); msgBuf.append(" with resultCode: ").append(resultCode).append(".\n\n").append(x.getMessage()); String msg = msgBuf.toString(); LOG.error(msg, x);
String renderTemplate(Change change, Template template, String namespace) { Map<String, String> value = values(change, namespace); try (StringWriter writer = new StringWriter()) { template.process(value, writer); return writer.toString(); } catch (IOException e) { throw new DataException("Exception while processing template", e); } catch (InvalidReferenceException e) { throw new DataException( String.format( "Exception thrown while processing template. Offending expression '%s'", e.getBlamedExpressionString() ), e); } catch (TemplateException e) { throw new DataException("Exception while processing template", e); } }
} else { if (exp != null) { throw InvalidReferenceException.getInstance(exp, env); } else { throw new InvalidReferenceException( "Null/missing value (no more informatoin avilable)", env);
/** * Used for assignments that use operators like {@code +=}, when the target variable was null/missing. */ static InvalidReferenceException getInstance(int scope, String missingAssignedVarName, String assignmentOperator, Environment env) { if (env != null && env.getFastInvalidReferenceExceptions()) { return FAST_INSTANCE; } else { final _ErrorDescriptionBuilder errDescBuilder = new _ErrorDescriptionBuilder( "The target variable of the assignment, ", new _DelayedJQuote(missingAssignedVarName), ", was null or missing in the " + Assignment.scopeAsString(scope) + ", and the \"", assignmentOperator, "\" operator must get its value from there before assigning to it." ); if (missingAssignedVarName.startsWith("$")) { errDescBuilder.tips(TIP_NO_DOLLAR, TIP_MISSING_ASSIGNMENT_TARGET); } else { errDescBuilder.tip(TIP_MISSING_ASSIGNMENT_TARGET); } return new InvalidReferenceException(errDescBuilder, env, null); } }
static TemplateException newNonDateException(Environment env, TemplateModel model, Expression target) throws InvalidReferenceException { TemplateException e; if (model == null) { e = InvalidReferenceException.getInstance(target, env); } else { e = new NonDateException(target, model, "date", env); } return e; }
String renderTemplate(Change change, Template template, String namespace) { Map<String, String> value = values(change, namespace); try (StringWriter writer = new StringWriter()) { template.process(value, writer); return writer.toString(); } catch (IOException e) { throw new DataException("Exception while processing template", e); } catch (InvalidReferenceException e) { throw new DataException( String.format( "Exception thrown while processing template. Offending expression '%s'", e.getBlamedExpressionString() ), e); } catch (TemplateException e) { throw new DataException("Exception while processing template", e); } }
final _ErrorDescriptionBuilder errDescBuilder = new _ErrorDescriptionBuilder("The following has evaluated to null or missing:").blame(blamed); if (endsWithDollarVariable(blamed)) { errDescBuilder.tips(TIP_NO_DOLLAR, TIP); } else if (blamed instanceof Dot) { errDescBuilder.tip(TIP); return new InvalidReferenceException(errDescBuilder, env, blamed); } else { return new InvalidReferenceException(env);
} else { if (exp != null) { throw InvalidReferenceException.getInstance(exp, env); } else { throw new InvalidReferenceException( "Null/missing value (no more informatoin avilable)", env);
static void assertNonNull(TemplateModel model, Expression exp, Environment env) throws InvalidReferenceException { if (model == null) { throw new InvalidReferenceException( "Expression " + exp + " is undefined " + exp.getStartLocation() + ".", env); } }
/** * @param blamedAssignmentTargetVarName * Used for assignments that use {@code +=} and such, in which case the {@code blamed} expression * parameter will be null {@code null} and this parameter will be non-{null}. */ private static _ErrorDescriptionBuilder newDesciptionBuilder( Expression blamed, String blamedAssignmentTargetVarName, TemplateModel model, String expectedTypesDesc, Class[] expectedTypes, Environment env) throws InvalidReferenceException { if (model == null) throw InvalidReferenceException.getInstance(blamed, env); _ErrorDescriptionBuilder errorDescBuilder = new _ErrorDescriptionBuilder( unexpectedTypeErrorDescription(expectedTypesDesc, blamed, blamedAssignmentTargetVarName, model)) .blame(blamed).showBlamer(true); if (model instanceof _UnexpectedTypeErrorExplainerTemplateModel) { Object[] tip = ((_UnexpectedTypeErrorExplainerTemplateModel) model).explainTypeError(expectedTypes); if (tip != null) { errorDescBuilder.tip(tip); } } if (model instanceof TemplateCollectionModel && (Arrays.asList(expectedTypes).contains(TemplateSequenceModel.class) || Arrays.asList(expectedTypes).contains(TemplateCollectionModelEx.class))) { errorDescBuilder.tip("As the problematic value contains a collection of items, you could convert it " + "to a sequence like someValue?sequence. Be sure though that you won't have a large number of " + "items, as all will be held in memory one the same time."); } return errorDescBuilder; }
private String executeInternal(String templateName, Object value) { Preconditions.checkNotNull(templateName, "templateName cannot be null."); Preconditions.checkNotNull(value, "values cannot be null."); Template template; try { template = this.configuration.getTemplate(templateName); } catch (IOException ex) { throw new DataException( String.format("Exception thrown while loading template '%s'", templateName), ex ); } try (StringWriter writer = new StringWriter()) { template.process(value, writer); return writer.toString(); } catch (IOException e) { throw new ConnectException("Exception while processing template", e); } catch (InvalidReferenceException e) { throw new DataException( String.format( "Exception thrown while processing template. Offending expression '%s'", e.getBlamedExpressionString() ), e); } catch (TemplateException e) { throw new ConnectException("Exception while processing template", e); } }
final _ErrorDescriptionBuilder errDescBuilder = new _ErrorDescriptionBuilder("The following has evaluated to null or missing:").blame(blamed); if (endsWithDollarVariable(blamed)) { errDescBuilder.tips(TIP_NO_DOLLAR, TIP); } else if (blamed instanceof Dot) { errDescBuilder.tip(TIP); return new InvalidReferenceException(errDescBuilder, env, blamed); } else { return new InvalidReferenceException(env);
static Number getNumber(TemplateModel model, Expression expr, Environment env) throws TemplateException { if(model instanceof TemplateNumberModel) { return getNumber((TemplateNumberModel)model, expr, env); } else if(model == null) { throw new InvalidReferenceException(expr + " is undefined.", env); } else { throw new NonNumericalException(expr + " is not a number, it is " + model.getClass().getName(), env); } }
throw InvalidReferenceException.getInstance(nameExp, env); } else { throw new NonUserDefinedDirectiveLikeException(nameExp, tm, env);
} catch (Exception e) { _logger.error(MessageFormat.format("Exception occurred while applying template change on {0}, with error message {1}.", templateString, e.getMessage())); generatedString = MessageFormat.format("ERROR occurred during applying template change to the following variable: {0}\n\n Detailed Message: {1}",((InvalidReferenceException) e).getBlamedExpressionString(), e.getMessage()); break;