terryyin / lizard

A simple code complexity analyser without caring about the C/C++ header files or Java imports, supports most of the popular languages.
Other
1.85k stars 250 forks source link

IndexError: pop from empty list #81

Closed erizhang closed 8 years ago

erizhang commented 8 years ago

Trying to calculate the complexity for a folder, the source files are huge. it prompts the error below:

➜  SS_ILEITP  lizard src > eitp_complexity
Traceback (most recent call last):
  File "/usr/bin/lizard", line 6, in <module>
    lizard_main(sys.argv)
  File "/usr/lib/python2.7/site-packages/lizard.py", line 974, in lizard_main
    printer(result, options, OutputScheme(options.extensions))
  File "/usr/lib/python2.7/site-packages/lizard.py", line 841, in print_result
    result = print_and_save_modules(result, option.extensions, scheme)
  File "/usr/lib/python2.7/site-packages/lizard.py", line 805, in print_and_save_modules
    for module_info in all_modules:
  File "/usr/lib/python2.7/site-packages/lizard.py", line 662, in __call__
    filename, open(filename, 'rU').read())
  File "/usr/lib/python2.7/site-packages/lizard.py", line 673, in analyze_source_code
    for _ in reader(tokens, reader):
  File "/usr/lib/python2.7/site-packages/lizard.py", line 378, in __call__
    self._state(token)
  File "/usr/lib/python2.7/site-packages/lizard.py", line 359, in read_until_matching_brackets
    func(self, token)
  File "/usr/lib/python2.7/site-packages/lizard.py", line 566, in _state_dec
    self.bracket_stack.pop()
IndexError: pop from empty list

and the result is dumped out for 181 lines.

terryyin commented 8 years ago

Oops, thans Eric!

I guess it's new. Let me investigate asap.

terryyin commented 8 years ago

Hey @erizhang,

I know where to fix the problem but could you please do me a favour to find which exact file failed lizard?

br, Terry

erizhang commented 8 years ago

@terryyin please check your private mail for file, and wechat for password.

terryyin commented 8 years ago

@erizhang fixed and released. But still, please review my fix: https://github.com/terryyin/lizard/commit/909df68c9092ae3a6e2a07e7af61a6e3789013d5

erizhang commented 8 years ago

Maybe you solved the return struct issue, but still has another one:

➜  SS_ILEITP  lizard src > eitp_complexity
Traceback (most recent call last):
  File "/usr/bin/lizard", line 6, in <module>
    lizard_main(sys.argv)
  File "/usr/lib/python2.7/site-packages/lizard.py", line 977, in lizard_main
    printer(result, options, OutputScheme(options.extensions))
  File "/usr/lib/python2.7/site-packages/lizard.py", line 844, in print_result
    result = print_and_save_modules(result, option.extensions, scheme)
  File "/usr/lib/python2.7/site-packages/lizard.py", line 808, in print_and_save_modules
    for module_info in all_modules:
  File "/usr/lib/python2.7/site-packages/lizard.py", line 665, in __call__
    filename, open(filename, 'rU').read())
  File "/usr/lib/python2.7/site-packages/lizard.py", line 676, in analyze_source_code
    for _ in reader(tokens, reader):
  File "/usr/lib/python2.7/site-packages/lizard.py", line 378, in __call__
    self._state(token)
  File "/usr/lib/python2.7/site-packages/lizard.py", line 359, in read_until_matching_brackets
    func(self, token)
  File "/usr/lib/python2.7/site-packages/lizard.py", line 569, in _state_dec
    self.bracket_stack.pop()
IndexError: pop from empty list

But notice that, if I deal the files one by one, the lizard works well, this issue is only produced when handle the files as batch.

terryyin commented 8 years ago

Hi Eric,

It’s highly unlikely that the problem is caused by multiple files. Could you please help me to investigate again? I’m counting on you, bro.

I could just add an if before self.bracket_stack.pop(), but don’t feel right to do it unless I know what causes the problem.

terry

On 15 Jan 2016, at 10:24 AM, Eric Zhang notifications@github.com wrote:

Maybe you solve the return struct issue, but still has another one:

➜ SS_ILEITP lizard src > eitp_complexity Traceback (most recent call last): File "/usr/bin/lizard", line 6, in lizard_main(sys.argv) File "/usr/lib/python2.7/site-packages/lizard.py", line 977, in lizard_main printer(result, options, OutputScheme(options.extensions)) File "/usr/lib/python2.7/site-packages/lizard.py", line 844, in print_result result = print_and_save_modules(result, option.extensions, scheme) File "/usr/lib/python2.7/site-packages/lizard.py", line 808, in print_and_save_modules for module_info in all_modules: File "/usr/lib/python2.7/site-packages/lizard.py", line 665, in call filename, open(filename, 'rU').read()) File "/usr/lib/python2.7/site-packages/lizard.py", line 676, in analyze_sourcecode for in reader(tokens, reader): File "/usr/lib/python2.7/site-packages/lizard.py", line 378, in call self._state(token) File "/usr/lib/python2.7/site-packages/lizard.py", line 359, in read_until_matching_brackets func(self, token) File "/usr/lib/python2.7/site-packages/lizard.py", line 569, in _state_dec self.bracket_stack.pop() IndexError: pop from empty list But notice that, if I deal the files one by one, the lizard works well, this issue is only produced when handle the files as batch.

— Reply to this email directly or view it on GitHub https://github.com/terryyin/lizard/issues/81#issuecomment-171849784.

terryyin commented 8 years ago

@erizhang could you please confirm and close the case?