ruslo/sugar

python generate_sugar_files.py fails with : TypeError: 'NoneType' object is not iterable

truedat101 opened this issue · 1 comments

To reproduce, create a directory foo. Run the script as below. It will fail with this error.

Assumption: NoneType object is not iterable is quite often a sign of some non-defensive code. In the particular case, its the args.exclude_dirs being accessed in an unsafe manner, as an iterator, with no default set for exclude_dirs = []. I'd suggest either set default args for exclude_dirs, or check first: if args.exclude_dirs is not None:

$ python generate_sugar_files.py --top ./foo/ --var MYPROJ_SOURCES
Traceback (most recent call last):
  File "generate_sugar_files.py", line 159, in <module>
    Generator.run()
  File "generate_sugar_files.py", line 156, in run
    generator.create()
  File "generate_sugar_files.py", line 116, in create
    for x in args.exclude_dirs:
TypeError: 'NoneType' object is not iterable

NOTE: The same command above works if I pass an --exclude_dirs argument to a valid directory to exclude.

ruslo commented

I'd suggest either set default args for exclude_dirs, or check first: if args.exclude_dirs is not None

Pull request with a fix is welcome, both approaches look good for me.