Skip to content

Commit

Permalink
Add undefined variable warning when config enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
manheychiu1 committed Apr 19, 2024
1 parent 61452e4 commit e2b4c07
Showing 1 changed file with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public class JinjavaInterpreter implements PyishSerializable {

public static final String IGNORED_OUTPUT_FROM_EXTENDS_NOTE =
"ignored_output_from_extends";

public static final String OUTPUT_UNDEFINED_VARIABLES_ERROR =
"OUTPUT_UNDEFINED_VARIABLES_ERROR";
private final Multimap<String, BlockInfo> blocks = ArrayListMultimap.create();
private final LinkedList<Node> extendParentRoots = new LinkedList<>();
private final Map<String, RevertibleObject> revertibleObjects = new HashMap<>();
Expand Down Expand Up @@ -585,6 +588,28 @@ public Object retraceVariable(String variable, int lineNumber, int startPosition
}
}
obj = var.resolve(obj);
} else {
if (
getConfig()
.getFeatures()
.getActivationStrategy(OUTPUT_UNDEFINED_VARIABLES_ERROR)
.isActive(getContext())
) {
addError(
new TemplateError(
ErrorType.WARNING,
ErrorReason.UNKNOWN,
ErrorItem.TOKEN,
"Undefined variable: '" + variable + "'",
null,
lineNumber,
startPosition,
null,
BasicTemplateErrorCategory.UNKNOWN,
ImmutableMap.of("variable", variable)
)
);
}
}
return obj;
}
Expand Down

0 comments on commit e2b4c07

Please sign in to comment.