Page MenuHomePhabricator

CosmeticChangesToolkit.removeEmptySections() may fail with IndexError
Open, LowPublic

Description

py -3.13 -m pwb -user:xqt cosmetic_changes -page:Tecklenburger_Land

1 read operation
Execution time: 2 seconds
Read operation time: 2.0 seconds
Script terminated by exception:

ERROR: list index out of range (IndexError)
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\pwb\GIT\core\pwb.py", line 40, in <module>
    sys.exit(main())
             ~~~~^^
  File "C:\pwb\GIT\core\pwb.py", line 36, in main
    runpy.run_path(str(path), run_name='__main__')
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen runpy>", line 287, in run_path
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "C:\pwb\GIT\core\pywikibot\scripts\wrapper.py", line 554, in <module>
    main()
    ~~~~^^
  File "C:\pwb\GIT\core\pywikibot\scripts\wrapper.py", line 538, in main
    if not execute():
           ~~~~~~~^^
  File "C:\pwb\GIT\core\pywikibot\scripts\wrapper.py", line 525, in execute
    run_python_file(filename, script_args, module)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\pwb\GIT\core\pywikibot\scripts\wrapper.py", line 154, in run_python_file
    exec(compile(source, filename, 'exec', dont_inherit=True),
    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         main_mod.__dict__)
         ^^^^^^^^^^^^^^^^^^
  File "C:\pwb\GIT\core\scripts\cosmetic_changes.py", line 131, in <module>
    main()
    ~~~~^^
  File "C:\pwb\GIT\core\scripts\cosmetic_changes.py", line 127, in main
    bot.run()
    ~~~~~~~^^
  File "C:\pwb\GIT\core\pywikibot\bot.py", line 1589, in run
    self.treat(page)
    ~~~~~~~~~~^^^^^^
  File "C:\pwb\GIT\core\pywikibot\bot.py", line 1836, in treat
    self.treat_page()
    ~~~~~~~~~~~~~~~^^
  File "C:\pwb\GIT\core\scripts\cosmetic_changes.py", line 85, in treat_page
    new_text = cc_toolkit.change(old_text)
  File "C:\pwb\GIT\core\pywikibot\cosmetic_changes.py", line 318, in change
    new_text = self._change(text)
  File "C:\pwb\GIT\core\pywikibot\cosmetic_changes.py", line 312, in _change
    text = self.safe_execute(method, text)
  File "C:\pwb\GIT\core\pywikibot\cosmetic_changes.py", line 298, in safe_execute
    result = method(text)
  File "C:\pwb\GIT\core\pywikibot\cosmetic_changes.py", line 749, in removeEmptySections
    current_dep = sections[i].level
                  ~~~~~~~~^^^
IndexError: list index out of range
CRITICAL: Exiting due to uncaught exception IndexError: list index out of range

Event Timeline

Change #1136118 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [bugfix] skip removeEmptySections() if section length is too less

https://gerrit.wikimedia.org/r/1136118

Change #1136118 merged by jenkins-bot:

[pywikibot/core@master] [bugfix] skip removeEmptySections() if section length is too less

https://gerrit.wikimedia.org/r/1136118

Xqt triaged this task as Low priority.May 5 2025, 2:29 AM