Add some error checking and handling
This commit is contained in:
@@ -77,11 +77,11 @@ class NovelModel(QAbstractTableModel):
|
|||||||
##
|
##
|
||||||
|
|
||||||
def rowCount(self, index: QModelIndex) -> int:
|
def rowCount(self, index: QModelIndex) -> int:
|
||||||
"""Return the number of rows for an entry."""
|
"""Return the number of rows."""
|
||||||
return len(self._rows)
|
return len(self._rows)
|
||||||
|
|
||||||
def columnCount(self, index: QModelIndex) -> int:
|
def columnCount(self, index: QModelIndex) -> int:
|
||||||
"""Return the number of columns for an entry."""
|
"""Return the number of columns."""
|
||||||
return self._columns
|
return self._columns
|
||||||
|
|
||||||
def data(self, index: QModelIndex, role: Qt.ItemDataRole) -> T_NodeData:
|
def data(self, index: QModelIndex, role: Qt.ItemDataRole) -> T_NodeData:
|
||||||
@@ -89,7 +89,7 @@ class NovelModel(QAbstractTableModel):
|
|||||||
try:
|
try:
|
||||||
return self._rows[index.row()].get(C_FACTOR*index.column() | role)
|
return self._rows[index.row()].get(C_FACTOR*index.column() | role)
|
||||||
except Exception:
|
except Exception:
|
||||||
print("NovelModel Debug: Oops!")
|
logger.error("Novel model index is inconsistent")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def handle(self, index: QModelIndex) -> str | None:
|
def handle(self, index: QModelIndex) -> str | None:
|
||||||
@@ -97,7 +97,7 @@ class NovelModel(QAbstractTableModel):
|
|||||||
try:
|
try:
|
||||||
return self._rows[index.row()].get(R_HANDLE) # type: ignore
|
return self._rows[index.row()].get(R_HANDLE) # type: ignore
|
||||||
except Exception:
|
except Exception:
|
||||||
print("NovelModel Debug: Oops!")
|
logger.error("Novel model index is inconsistent")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def key(self, index: QModelIndex) -> str | None:
|
def key(self, index: QModelIndex) -> str | None:
|
||||||
@@ -105,7 +105,7 @@ class NovelModel(QAbstractTableModel):
|
|||||||
try:
|
try:
|
||||||
return self._rows[index.row()].get(R_KEY) # type: ignore
|
return self._rows[index.row()].get(R_KEY) # type: ignore
|
||||||
except Exception:
|
except Exception:
|
||||||
print("NovelModel Debug: Oops!")
|
logger.error("Novel model index is inconsistent")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -134,12 +134,17 @@ class NovelModel(QAbstractTableModel):
|
|||||||
current.append(i)
|
current.append(i)
|
||||||
|
|
||||||
if current == []:
|
if current == []:
|
||||||
|
logger.warning("No novel model entries for '%s'", handle)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
cols = self._columns - 1
|
cols = self._columns - 1
|
||||||
|
|
||||||
first = current[0]
|
first = current[0]
|
||||||
last = current[-1]
|
last = current[-1]
|
||||||
|
|
||||||
|
if len(current) != last - first + 1:
|
||||||
|
logger.warning("Novel model entries for '%s' are not continuous", handle)
|
||||||
|
return False
|
||||||
|
|
||||||
remains = []
|
remains = []
|
||||||
try:
|
try:
|
||||||
for key, head in node.items():
|
for key, head in node.items():
|
||||||
@@ -165,6 +170,7 @@ class NovelModel(QAbstractTableModel):
|
|||||||
except Exception:
|
except Exception:
|
||||||
# This is faster than to check for index boundaries.
|
# This is faster than to check for index boundaries.
|
||||||
# We definitely don't want to cause a crash.
|
# We definitely don't want to cause a crash.
|
||||||
|
logger.error("Novel model refresh error for '%s'", handle)
|
||||||
logException()
|
logException()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user