otsaloma / gaupol

Editor for text-based subtitle files
https://otsaloma.io/gaupol/
GNU General Public License v3.0
251 stars 34 forks source link

Traceback when clicking the replace button #165

Closed sbraz closed 3 years ago

sbraz commented 4 years ago

Hi Osmo, It's not the first time I run into this exception but I am not exactly sure what triggers it. I am simply clicking "replace" or "replace all" and I get this:

Traceback

File: /usr/lib/python3.7/site-packages/gaupol/dialogs/spell_check.py
Line: 183
In: _on_replace_button_clicked

    self._navigator.replace(self._entry.get_text())

File: /usr/lib/python3.7/site-packages/aeidon/spell.py
Line: 217
In: replace

    self.text = self.text[:self.pos] + replacement + self.text[self.endpos:]

File: /usr/lib/python3.7/site-packages/aeidon/spell.py
Line: 185
In: endpos

    return self.pos + len(self.word)

TypeError: object of type 'NoneType' has no len()

Environment

Platform: Linux-5.8.9-gentoo-x86_64-x86_64-Intel-R-_Core-TM-_i9-9900K_CPU_@_3.60GHz-with-gentoo-2.7
Locale: en_US.utf_8

Versions

aeidon: 1.8
chardet: 3.0.4
gaupol: 1.8
gspell: 1
gstreamer: 1.16.2.0
gtk+: 3.24.22
pygobject: 3.36.1
python: 3.7.9

The word I am replacing is pretty normal, I don't know why it would be None. The replacement is performed too, I can see it in the edited subtitle.

It seems to happen near the end of the spellcheck. After the exception happens, I cannot click ignore either, I get a similar error:

Traceback

File: /usr/lib/python3.7/site-packages/gaupol/dialogs/spell_check.py
Line: 163
In: _on_ignore_button_clicked

    self._navigator.ignore()

File: /usr/lib/python3.7/site-packages/aeidon/spell.py
Line: 189
In: ignore

    self.pos = self.endpos

File: /usr/lib/python3.7/site-packages/aeidon/spell.py
Line: 185
In: endpos

    return self.pos + len(self.word)

TypeError: object of type 'NoneType' has no len()

If I click "edit", the text that appears in the box is a few dozen lines later.

Even closing the spellcheck window triggers an exception:

Traceback

File: /usr/lib/python3.7/site-packages/gaupol/dialogs/spell_check.py
Line: 190
In: _on_response

    self._set_done()

File: /usr/lib/python3.7/site-packages/gaupol/dialogs/spell_check.py
Line: 282
In: _set_done

    self._navigator.checker.write_replacements()

File: /usr/lib/python3.7/site-packages/aeidon/spell.py
Line: 137
In: write_replacements

    text = "\n".join("|".join(x) for x in replacements) + "\n"

File: /usr/lib/python3.7/site-packages/aeidon/spell.py
Line: 137
In: <genexpr>

    text = "\n".join("|".join(x) for x in replacements) + "\n"

TypeError: sequence item 0: expected str instance, NoneType found
otsaloma commented 4 years ago

I can't reproduce this and don't remember ever seeing it.

That word is set to None when the navigation status is reset, i.e. a new subtitle is assigned, cursor set to beginning and no misspelled word yet found. The dialog should be iterating over misspelled words and thus providing actions only when there is a misspelled word. Somehow the navigation state gets confused here, but I can't tell how.

https://github.com/otsaloma/gaupol/blob/master/aeidon/spell.py#L229