}
-class NotFoundException(BaseException):
- """Call on DB fetches finding less than expected."""
+class NotFoundException(Exception):
+ """Call on expected data missing, e.g. DB fetches finding nothing."""
+
+
+class CantWriteException(Exception):
+ """Call when there's an obstacle to expected writing of data."""
def _ensure_expected_dirs(expected_dirs: list[PathStr]) -> None:
makedirs(dir_name)
elif not isdir(dir_name):
msg = f'at expected directory path {dir_name} found non-directory'
- raise Exception(msg)
+ raise CantWriteException(msg)
class DatabaseConnection:
sql = SqlText(f'SELECT * FROM {cls._table_name} WHERE id = ?')
row = conn.exec(sql, (id_,)).fetchone()
if not row:
- raise NotFoundException
+ msg = f'no entry found for ID "{id_}" in table {cls._table_name}'
+ raise NotFoundException(msg)
return cls._from_table_row(row)
@classmethod
sql = SqlText(f'SELECT * FROM {cls._table_name} WHERE yt_id = ?')
row = conn.exec(sql, (yt_id,)).fetchone()
if not row:
- raise NotFoundException
+ raise NotFoundException(f'no entry for file to Youtube ID {yt_id}')
return cls._from_table_row(row)
@property
self._send_last_playlist_update()
else: # e.g. for /
self._send_playlist()
- except NotFoundException:
- self._send_http(b'not found', code=404)
+ except NotFoundException as e:
+ self._send_http(bytes(str(e), 'utf8'), code=404)
def _send_rendered_template(self,
tmpl_name: PathStr,