Skip to content

Commit

Permalink
improved diagnostic info
Browse files Browse the repository at this point in the history
  • Loading branch information
javalc6 committed Jun 11, 2023
1 parent a83b7d1 commit 8d7d1f6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
5 changes: 4 additions & 1 deletion wiki/TemplateParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private void template_body(WikiScanner sh, StringBuilder sb, WikiPage wp, Frame
rep = invocation_body(sh, wp, parent);
}
if (rep == null) {
sh.dumpString("Ops, something wrong!");
sh.dumpString("Unexpected error, probably caused by unbalanced curly brackets");
sh.setPointer(p2);
} else {
int end = sh.getPointer();
Expand Down Expand Up @@ -136,6 +136,9 @@ private boolean parameter_holder(WikiScanner sh, StringBuilder sb, WikiPage wp,
if (param_name != null) {
String result = parent == null ? null : parent.getTemplateParameter(param_name);
String def_value = sh.getChar('|') ? sh.getStringParameter(null) : null;
while (sh.getChar('|')) {//ignore any further parameter(s)
sh.getStringParameter(null);
}
if (sh.getSequence("}}}")) {
if (result == null)
result = def_value == null ? "{{{" + param_name + "}}}" : parseParameter(def_value, wp, parent);//use literal or default value
Expand Down
7 changes: 6 additions & 1 deletion wiki/TestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ private void do_parser_eval_tests(TemplateParser tp) throws ParseException {//au
testEvaluate(tp, "{{#ifeq: 1233.00 | 1233 |equal | not}}", wp, "equal");
// testEvaluate(tp, "{{#time: Y-m-d }}", wp, "2024-01-01");
testEvaluate(tp, "{{#time:d F Y|1988-02-28|nl}}", wp, "28 februari 1988");
testEvaluate(tp, "{{#time: r|2000 December 20}}", wp, "<span class=\"error\">textbook:2000 December 20</span>");
testEvaluate(tp, "{{#time: r|26. Oct 81}}", wp, "Mon, 26 Oct 1981 00:00:00 +0000");
testEvaluate(tp, "{{#time: r|26 Oct 1981, 12:49:16}}", wp, "Mon, 26 Oct 1981 12:49:16 +0000");
testEvaluate(tp, "{{#time: r|Oct 26th 1981}}", wp, "Mon, 26 Oct 1981 00:00:00 +0000");
testEvaluate(tp, "{{#time: r|October 26 1981}}", wp, "Mon, 26 Oct 1981 00:00:00 +0000");
testEvaluate(tp, "{{#time: r|26.10.1981}}", wp, "Mon, 26 Oct 1981 00:00:00 +0000");
testEvaluate(tp, "{{#time: r|2000 December 20}}", wp, "<strong class=\"error\">textbook:2000 December 20</strong>");
testEvaluate(tp, "{{#iferror: {{#time: Y-m-d }} | error | correct }}", wp, "correct");
testEvaluate(tp, "{{#iferror: {{#time: r|2000 December 20}} | error | correct }}", wp, "error");
testEvaluate(tp, "{{#titleparts: Talk:Foo/bar/baz/quok | 2 | 2 }}", wp, "bar/baz");
Expand Down
10 changes: 4 additions & 6 deletions wiki/parserfunctions/Invoke.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public String evaluate(WikiPage wp, ArrayList<String> parameters, Frame parent)
boolean trace_calls = wp.getTrace_calls();
String module_name = tp.parseParameter( parameters.get(0), wp, parent);
String function_name = tp.parseParameter( parameters.get(1), wp, parent);
if (trace_calls)
System.out.print("MODULE:" + module_name + "." + function_name + "(");
Map<String, String> parameterMap = new LinkedHashMap<>();//skip first two parameter (module and function names)
int pos = 1;
for (int i = 2; i < parameters.size(); i++) {
Expand All @@ -68,13 +66,13 @@ public String evaluate(WikiPage wp, ArrayList<String> parameters, Frame parent)
parameterMap.put(Integer.toString(pos++), param);//unnamed parameter
}
}
if (trace_calls) {
System.out.println(parameterMap);
System.out.println(")");
}
if (trace_calls)
System.out.println("MODULE:" + module_name + "." + function_name + "(" + parameterMap + ")");
try {
return sle.invoke(module_name, function_name, parent, parameterMap, trace_calls);
} catch (LuaError | ScribuntoException ex) {
if (!trace_calls)
System.out.println("MODULE:" + module_name + "." + function_name + "(" + parameterMap + ")");
ex.printStackTrace();//debugging
return format_error("Module error: " + ex.getMessage());
}
Expand Down
2 changes: 1 addition & 1 deletion wiki/parserfunctions/Time.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public String evaluate(WikiPage wp, ArrayList<String> parameters, Frame parent)
try {
date = new StringToTime(dateTimeParameter);
} catch (StringToTimeException e) {
return "<span class=\"error\">"+wp.getPagename()+":"+dateTimeParameter+"</span>";
return format_error(wp.getPagename()+":"+dateTimeParameter);
}
} else {
date = new Date(System.currentTimeMillis());
Expand Down

0 comments on commit 8d7d1f6

Please sign in to comment.