From f98bed108597603d29d7b0f4d5ba4c4ea7e17d4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Verg=C3=A9?= Date: Mon, 21 Mar 2016 21:56:07 +0100 Subject: [PATCH] Rules: indentation: Do not crash on unexpected token Previously, when the indentation rule blocked on an unexpected token, the program crashed with something like: File "/usr/lib/python3/dist-packages/yamllint/rules/indentation.py", line 434, in check assert context['stack'][-1].type == KEY AssertionError Instead, we prefer report the error as a regular `LintProblem` and continue processing. Fixes: #3 --- yamllint/rules/indentation.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/yamllint/rules/indentation.py b/yamllint/rules/indentation.py index 15f57d2..f975bcc 100644 --- a/yamllint/rules/indentation.py +++ b/yamllint/rules/indentation.py @@ -295,7 +295,7 @@ def check_scalar_indentation(conf, token, context): (expected_indent, indent)) -def check(conf, token, prev, next, nextnext, context): +def _check(conf, token, prev, next, nextnext, context): if 'stack' not in context: context['stack'] = [Parent(ROOT, 0)] context['cur_line'] = -1 @@ -541,3 +541,13 @@ def check(conf, token, prev, next, nextnext, context): else: break + + +def check(conf, token, prev, next, nextnext, context): + try: + for problem in _check(conf, token, prev, next, nextnext, context): + yield problem + except AssertionError: + yield LintProblem(token.start_mark.line + 1, + token.start_mark.column + 1, + 'cannot infer indentation: unexpected token')