From 7b6a730abc5234ac27f23b7c4dfca34522135b8d Mon Sep 17 00:00:00 2001 From: Erez Sh Date: Sun, 6 Dec 2020 14:30:32 -0500 Subject: [PATCH] Small bugfixes in exceptions --- lark/exceptions.py | 3 ++- lark/lark.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lark/exceptions.py b/lark/exceptions.py index 23e78b9..d9204b9 100644 --- a/lark/exceptions.py +++ b/lark/exceptions.py @@ -120,7 +120,8 @@ class UnexpectedInput(LarkError): def _format_expected(self, expected): if self._terminals_by_name: - expected = [self._terminals_by_name[t_name].user_repr() for t_name in expected] + d = self._terminals_by_name + expected = [d[t_name].user_repr() if t_name in d else t_name for t_name in expected] return "Expected one of: \n\t* %s\n" % '\n\t* '.join(expected) diff --git a/lark/lark.py b/lark/lark.py index c08eae6..80327d9 100644 --- a/lark/lark.py +++ b/lark/lark.py @@ -265,7 +265,10 @@ class Lark(Serialize): for name in (set(options) - _LOAD_ALLOWED_OPTIONS): del options[name] with FS.open(cache_fn, 'rb') as f: - self._load(f, **options) + try: + self._load(f, **options) + except Exception: + raise RuntimeError("Failed to load Lark from cache: %r. Try to delete the file and run again." % cache_fn) return if self.options.lexer == 'auto':