public _MiscTemplateException(Expression blamed, Throwable cause, Environment env, String description) { super(cause, env, blamed, new _ErrorDescriptionBuilder(description).blame(blamed)); }
public _TemplateModelException(Expression blamed, Throwable cause, Environment env, Object... descriptionParts) { super(cause, env, new _ErrorDescriptionBuilder(descriptionParts).blame(blamed), true); }
public _TemplateModelException(Expression blamed, Throwable cause, Environment env, String description) { super(cause, env, new _ErrorDescriptionBuilder(description).blame(blamed), true); }
public _MiscTemplateException(Expression blamed, Throwable cause, Environment env, Object... descriptionParts) { super(cause, env, blamed, new _ErrorDescriptionBuilder(descriptionParts).blame(blamed)); }
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); } }
protected void checkDateTypeNotUnknown(int dateType) throws TemplateException { if (dateType == TemplateDateModel.UNKNOWN) { throw new _MiscTemplateException(new _ErrorDescriptionBuilder( "The value of the following has unknown date type, but ?", key, " needs a value where it's known if it's a date (no time part), time, or date-time value:" ).blame(target).tip(_MessageUtil.UNKNOWN_DATE_TYPE_ERROR_TIP)); } }
public static _TemplateModelException newCantFormatUnknownTypeDateException( Expression dateSourceExpr, UnknownDateTypeFormattingUnsupportedException cause) { return new _TemplateModelException(cause, null, new _ErrorDescriptionBuilder( _MessageUtil.UNKNOWN_DATE_TO_STRING_ERROR_MESSAGE) .blame(dateSourceExpr) .tips(_MessageUtil.UNKNOWN_DATE_TO_STRING_TIPS)); }
/** * @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; }
static NonNumericalException newMalformedNumberException(Expression blamed, String text, Environment env) { return new NonNumericalException( new _ErrorDescriptionBuilder("Can't convert this string to number: ", new _DelayedJQuote(text)) .blame(blamed), env); }
public static TemplateException newCantFormatDateException(TemplateDateFormat format, Expression dataSrcExp, TemplateValueFormatException e, boolean useTempModelExc) { _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( "Failed to format date/time/datetime with format ", new _DelayedJQuote(format.getDescription()), ": ", e.getMessage()) .blame(dataSrcExp); return useTempModelExc ? new _TemplateModelException(e, (Environment) null, desc) : new _MiscTemplateException(e, (Environment) null, desc); }
public static TemplateException newCantFormatNumberException(TemplateNumberFormat format, Expression dataSrcExp, TemplateValueFormatException e, boolean useTempModelExc) { _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( "Failed to format number with format ", new _DelayedJQuote(format.getDescription()), ": ", e.getMessage()) .blame(dataSrcExp); return useTempModelExc ? new _TemplateModelException(e, (Environment) null, desc) : new _MiscTemplateException(e, (Environment) null, desc); }
private static String ensureFormatResultString(Object formatResult, Expression exp, Environment env) throws NonStringException { if (formatResult instanceof String) { return (String) formatResult; } assertFormatResultNotNull(formatResult); TemplateMarkupOutputModel mo = (TemplateMarkupOutputModel) formatResult; _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( "Value was formatted to convert it to string, but the result was markup of ouput format ", new _DelayedJQuote(mo.getOutputFormat()), ".") .tip("Use value?string to force formatting to plain text.") .blame(exp); throw new NonStringException(null, desc); }
if (blamed != null) { final _ErrorDescriptionBuilder errDescBuilder = new _ErrorDescriptionBuilder("The following has evaluated to null or missing:").blame(blamed); if (endsWithDollarVariable(blamed)) { errDescBuilder.tips(TIP_NO_DOLLAR, TIP);
/** * Convenience wrapper around {@link #getTemplateNumberFormat(String)} to be called during expression evaluation. * * @param exp * The blamed expression if an error occurs; it's only needed for better error messages */ TemplateNumberFormat getTemplateNumberFormat(String formatString, Expression exp, boolean useTempModelExc) throws TemplateException { TemplateNumberFormat format; try { format = getTemplateNumberFormat(formatString); } catch (TemplateValueFormatException e) { _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( "Failed to get number format object for the ", new _DelayedJQuote(formatString), " number format string: ", e.getMessage()) .blame(exp); throw useTempModelExc ? new _TemplateModelException(e, this, desc) : new _MiscTemplateException(e, this, desc); } return format; }
/** * Convenience wrapper around {@link #getTemplateNumberFormat()} to be called during expression evaluation. */ TemplateNumberFormat getTemplateNumberFormat(Expression exp, boolean useTempModelExc) throws TemplateException { TemplateNumberFormat format; try { format = getTemplateNumberFormat(); } catch (TemplateValueFormatException e) { _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( "Failed to get number format object for the current number format string, ", new _DelayedJQuote(getNumberFormat()), ": ", e.getMessage()) .blame(exp); throw useTempModelExc ? new _TemplateModelException(e, this, desc) : new _MiscTemplateException(e, this, desc); } return format; }
/** * Same as {@link #getTemplateDateFormat(String, int, Class)}, but translates the exceptions to * {@link TemplateException}-s. */ TemplateDateFormat getTemplateDateFormat( String formatString, int dateType, Class<? extends Date> dateClass, Expression blamedDateSourceExp, Expression blamedFormatterExp, boolean useTempModelExc) throws TemplateException { try { return getTemplateDateFormat(formatString, dateType, dateClass); } catch (UnknownDateTypeFormattingUnsupportedException e) { throw _MessageUtil.newCantFormatUnknownTypeDateException(blamedDateSourceExp, e); } catch (TemplateValueFormatException e) { _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( "Can't create date/time/datetime format based on format string ", new _DelayedJQuote(formatString), ". Reason given: ", e.getMessage()) .blame(blamedFormatterExp); throw useTempModelExc ? new _TemplateModelException(e, desc) : new _MiscTemplateException(e, desc); } }
", TemplateModel class: ", new _DelayedShortClassName(tm.getClass()), ", ObjectWapper: ", new _DelayedToString(env.getObjectWrapper()), ")" ).blame(blamedExpr);
public static _TemplateModelException newCantFormatUnknownTypeDateException( Expression dateSourceExpr, UnknownDateTypeFormattingUnsupportedException cause) { return new _TemplateModelException(cause, null, new _ErrorDescriptionBuilder( _MessageUtil.UNKNOWN_DATE_TO_STRING_ERROR_MESSAGE) .blame(dateSourceExpr) .tips(_MessageUtil.UNKNOWN_DATE_TO_STRING_TIPS)); }
protected void checkDateTypeNotUnknown(int dateType) throws TemplateException { if (dateType == TemplateDateModel.UNKNOWN) { throw new _MiscTemplateException(new _ErrorDescriptionBuilder( "The value of the following has unknown date type, but ?", key, " needs a value where it's known if it's a date (no time part), time, or date-time value:" ).blame(target).tip(_MessageUtil.UNKNOWN_DATE_TYPE_ERROR_TIP)); } }
public static TemplateException newCantFormatNumberException(TemplateNumberFormat format, Expression dataSrcExp, TemplateValueFormatException e, boolean useTempModelExc) { _ErrorDescriptionBuilder desc = new _ErrorDescriptionBuilder( "Failed to format number with format ", new _DelayedJQuote(format.getDescription()), ": ", e.getMessage()) .blame(dataSrcExp); return useTempModelExc ? new _TemplateModelException(e, (Environment) null, desc) : new _MiscTemplateException(e, (Environment) null, desc); }