Check return values (e.g. indexOf)

This commit is contained in:
Florian Bruhin 2014-06-22 23:33:32 +02:00
parent ef5b16556b
commit 4bd8a596f1
3 changed files with 25 additions and 6 deletions

View File

@ -77,7 +77,9 @@ class BaseCompletionModel(QStandardItemModel):
qt_ensure_valid(index)
haystack = self.data(index)
marks = self._get_marks(needle, haystack)
self.setData(index, marks, Role.marks)
ok = self.setData(index, marks, Role.marks)
if not ok:
raise ValueError("Error while setting data!")
def new_category(self, name, sort=None):
"""Add a new category to the model.

View File

@ -88,7 +88,10 @@ class SettingOptionCompletionModel(BaseCompletionModel):
val = config.get(section, option, raw=True)
idx = item.index()
qt_ensure_valid(idx)
self.setData(idx, val, Qt.DisplayRole)
ok = self.setData(idx, val, Qt.DisplayRole)
if not ok:
raise ValueError("Setting data failed! (section: {}, option: {}, "
"value: {})".format(section, option, val))
class SettingValueCompletionModel(BaseCompletionModel):
@ -127,7 +130,10 @@ class SettingValueCompletionModel(BaseCompletionModel):
value = '""'
idx = self.cur_item.index()
qt_ensure_valid(idx)
self.setData(idx, value, Qt.DisplayRole)
ok = self.setData(idx, value, Qt.DisplayRole)
if not ok:
raise ValueError("Setting data failed! (section: {}, option: {}, "
"value: {})".format(section, option, value))
class CommandCompletionModel(BaseCompletionModel):

View File

@ -342,7 +342,10 @@ class TabbedBrowser(TabWidget):
Args:
tab: The tab where the signal belongs to.
"""
self.setTabIcon(self.indexOf(tab), EmptyTabIcon())
idx = self.indexOf(tab)
if idx == -1:
raise ValueError("Tab {} not found!".format(tab))
self.setTabIcon(idx, EmptyTabIcon())
@pyqtSlot(WebView, str)
def on_title_changed(self, tab, text):
@ -356,7 +359,10 @@ class TabbedBrowser(TabWidget):
"""
log.webview.debug("title changed to '{}'".format(text))
if text:
self.setTabText(self.indexOf(tab), text)
idx = self.indexOf(tab)
if idx == -1:
raise ValueError("Tab {} not found!".format(tab))
self.setTabText(idx, text)
else:
log.webview.debug("ignoring title change")
@ -369,6 +375,8 @@ class TabbedBrowser(TabWidget):
url: The new URL.
"""
idx = self.indexOf(tab)
if idx == -1:
raise ValueError("Tab {} not found!".format(tab))
if not self.tabText(idx):
self.setTabText(idx, url)
@ -383,7 +391,10 @@ class TabbedBrowser(TabWidget):
"""
if not config.get('tabbar', 'show-favicons'):
return
self.setTabIcon(self.indexOf(tab), tab.icon())
idx = self.indexOf(tab)
if idx == -1:
raise ValueError("Tab {} not found!".format(tab))
self.setTabIcon(idx, tab.icon())
@pyqtSlot(str)
def on_mode_left(self, mode):