yamllint icon indicating copy to clipboard operation
yamllint copied to clipboard

Crashed when validating a yaml file with a "TypeError ... a number is required, not NoneType"

Open muhammadamhan1 opened this issue 4 years ago • 5 comments

I started using yamllint on Ubuntu 18.04, and it's pretty good tool. While I was doing some local experiments to build a custom rules config, it crashed in one of my test scenarios as shown below:

Simply running yamllint on example.yaml:

---

- test: 
    foo: hello,
    bar: world,
}

will result in:

Traceback (most recent call last):
  File "/usr/bin/yamllint", line 11, in <module>
    load_entry_point('yamllint==1.10.0', 'console_scripts', 'yamllint')()
  File "/usr/lib/python3/dist-packages/yamllint/cli.py", line 143, in run
    for problem in linter.run(f, conf, filepath):
  File "/usr/lib/python3/dist-packages/yamllint/linter.py", line 196, in _run
    for problem in get_cosmetic_problems(buffer, conf, filepath):
  File "/usr/lib/python3/dist-packages/yamllint/linter.py", line 140, in get_cosmetic_problems
    context[rule.ID]):
  File "/usr/lib/python3/dist-packages/yamllint/rules/indentation.py", line 567, in check
    for problem in _check(conf, token, prev, next, nextnext, context):
  File "/usr/lib/python3/dist-packages/yamllint/rules/indentation.py", line 334, in _check
    (expected, found_indentation))
TypeError: %d format: a number is required, not NoneType

Steps to reproduce:

Given a *.yaml file, include a closing curly braces character } without an opening end. yamllint should correctly mark it as invalid. For any other special character, including an opening curly braces { without a closing end, yamllint will correctly invalidate the file.

I tried looking for a similar existing issue but couldn't find one, so hopefully this isn't a duplicate.

muhammadamhan1 avatar Jan 04 '21 11:01 muhammadamhan1

I might be using an old version. Will report back.

muhammadamhan1 avatar Jan 04 '21 12:01 muhammadamhan1

Ran the project locally from master it's the same issue.

muhammadamhan1 avatar Jan 04 '21 12:01 muhammadamhan1

Hello,

Thanks for reporting the bug. It comes from the indentation rule, because disabling it reports a syntax error (as expected):

$ yamllint -d '{extends: default, rules: {indentation: disable}}' problem.yaml
problem.yaml
  6:1       error    syntax error: expected <block end>, but found '}' (syntax)

Any contribution to fix this (with a new test case) is welcome.

adrienverge avatar Jan 04 '21 16:01 adrienverge

same problem here

bmillemathias avatar Jun 08 '21 09:06 bmillemathias

Same problem in https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1004469

debalance avatar Jun 11 '22 23:06 debalance