Add exception handlers in places where scripts are invoked. This should lead to slightly nicer error messages.

This commit is contained in:
Twan van Laarhoven
2020-05-22 00:30:18 +02:00
parent 8b91cd8804
commit c9c7a958ae
5 changed files with 38 additions and 14 deletions
+7 -3
View File
@@ -246,9 +246,13 @@ String KeywordsPanel::runRefScript(int find_i) {
} else {
FOR_EACH(r, p->refer_scripts) {
if (i++ == find_i) {
Context& ctx = set->getContext();
ctx.setVariable(SCRIPT_VAR_input, to_script(param_s));
return r->script.invoke(ctx)->toString();
try {
Context& ctx = set->getContext();
ctx.setVariable(SCRIPT_VAR_input, to_script(param_s));
return r->script.invoke(ctx)->toString();
} catch (ScriptError const& e) {
handle_error(ScriptError(e.what() + _("\n in keyword refer script '") + r->name + _("'")));
}
}
}
}
+10 -6
View File
@@ -480,12 +480,16 @@ void StatsPanel::showCategory(const GraphType* prefer_layout) {
GraphElementP e(new GraphElement(i));
bool show = true;
FOR_EACH(dim, dims) {
String value = untag(dim->script.invoke(ctx)->toString());
e->values.push_back(value);
if (value.empty() && !dim->show_empty) {
// don't show this element
show = false;
break;
try {
String value = untag(dim->script.invoke(ctx)->toString());
e->values.push_back(value);
if (value.empty() && !dim->show_empty) {
// don't show this element
show = false;
break;
}
} catch (ScriptError const& e) {
handle_error(ScriptError(e.what() + _("\n in script for statistics dimension '") + dim->name + _("'")));
}
}
if (show) {