From a2d78941ba8d199ffbaa4b7b102a45312c78fcf7 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 9 Nov 2015 08:42:40 +0000 Subject: [PATCH] Catch expression evaluation errors in line/column highlighters --- src/highlighters.cc | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/highlighters.cc b/src/highlighters.cc index 17f32cf4..a2e8e662 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -478,14 +478,24 @@ HighlighterAndId create_line_highlighter(HighlighterParameters params) throw runtime_error("wrong parameter count"); String facespec = params[1]; - String option_name = params[0]; + String line_expr = params[0]; get_face(facespec); // validate facespec auto func = [=](const Context& context, HighlightFlags flags, DisplayBuffer& display_buffer, BufferRange) { - const LineCount line = str_to_int_ifp(expand(option_name, context)).value_or(0) - 1; + LineCount line = -1; + try + { + line = str_to_int_ifp(expand(line_expr, context)).value_or(0) - 1; + } + catch (runtime_error& err) + { + write_to_debug_buffer( + format("Error evaluating highlight line expression: {}", err.what())); + } + if (line < 0) return; @@ -520,14 +530,24 @@ HighlighterAndId create_column_highlighter(HighlighterParameters params) throw runtime_error("wrong parameter count"); String facespec = params[1]; - String option_name = params[0]; + String col_expr = params[0]; get_face(facespec); // validate facespec auto func = [=](const Context& context, HighlightFlags flags, DisplayBuffer& display_buffer, BufferRange) { - const CharCount column = str_to_int_ifp(expand(option_name, context)).value_or(0) - 1; + CharCount column = -1; + try + { + column = str_to_int_ifp(expand(col_expr, context)).value_or(0) - 1; + } + catch (runtime_error& err) + { + write_to_debug_buffer( + format("Error evaluating highlight column expression: {}", err.what())); + } + if (column < 0) return;