more defensive error handling -- token marker must not crash;
authorwenzelm
Mon, 06 Oct 2014 18:11:16 +0200
changeset 58595 127f192b755c
parent 58594 72e2f0e7e344
child 58596 877c5ecee253
more defensive error handling -- token marker must not crash;
src/Tools/jEdit/src/bibtex_jedit.scala
--- a/src/Tools/jEdit/src/bibtex_jedit.scala	Mon Oct 06 17:27:27 2014 +0200
+++ b/src/Tools/jEdit/src/bibtex_jedit.scala	Mon Oct 06 18:11:16 2014 +0200
@@ -171,19 +171,26 @@
         }
       val line = if (raw_line == null) new Segment else raw_line
 
+      def no_markup =
+      {
+        val styled_token = (JEditToken.NULL, line.subSequence(0, line.count).toString)
+        (List(styled_token), new Line_Context(None))
+      }
+
       val context1 =
       {
         val (styled_tokens, context1) =
           line_ctxt match {
             case Some(ctxt) =>
-              val (chunks, ctxt1) = Bibtex.parse_line(line, ctxt)
-              val styled_tokens =
-                for { chunk <- chunks; tok <- chunk.tokens }
-                yield (token_style(chunk.kind, tok), tok.source)
-              (styled_tokens, new Line_Context(Some(ctxt1)))
-            case None =>
-              val styled_token = (JEditToken.NULL, line.subSequence(0, line.count).toString)
-              (List(styled_token), new Line_Context(None))
+              try {
+                val (chunks, ctxt1) = Bibtex.parse_line(line, ctxt)
+                val styled_tokens =
+                  for { chunk <- chunks; tok <- chunk.tokens }
+                  yield (token_style(chunk.kind, tok), tok.source)
+                (styled_tokens, new Line_Context(Some(ctxt1)))
+              }
+              catch { case ERROR(msg) => Output.warning(msg); no_markup }
+            case None => no_markup
           }
 
         var offset = 0
@@ -244,7 +251,7 @@
         }
         data
       }
-      catch { case ERROR(_) => null }
+      catch { case ERROR(msg) => Output.warning(msg); null }
     }
   }
 }