Skip to content

Commit

Permalink
Merge pull request #4903 from daschuer/dao_assert
Browse files Browse the repository at this point in the history
log messages before asserting in DAO classes.
  • Loading branch information
Holzhaus authored Aug 22, 2022
2 parents 3655776 + 67171d2 commit 074c938
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 44 deletions.
3 changes: 2 additions & 1 deletion src/analyzer/plugins/analyzerqueenmarykey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ bool AnalyzerQueenMaryKey::initialize(mixxx::audio::SampleRate sampleRate) {
windowSize, stepSize, [this](double* pWindow, size_t) {
int iKey = m_pKeyMode->process(pWindow);

VERIFY_OR_DEBUG_ASSERT(ChromaticKey_IsValid(iKey)) {
if (!ChromaticKey_IsValid(iKey)) {
qWarning() << "No valid key detected in analyzed window:" << iKey;
DEBUG_ASSERT(!"iKey is invalid");
return false;
}
const auto key = static_cast<ChromaticKey>(iKey);
Expand Down
18 changes: 12 additions & 6 deletions src/library/dao/autodjcratesdao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,9 @@ TrackId AutoDJCratesDAO::getRandomTrackId() {
" WHERE " AUTODJCRATESTABLE_TIMESPLAYED
" = 0 UNION ALL SELECT COUNT(*) AS count FROM "
AUTODJACTIVETRACKS_TABLE);
VERIFY_OR_DEBUG_ASSERT(oQuery.exec()) {
if (!oQuery.exec()) {
LOG_FAILED_QUERY(oQuery);
DEBUG_ASSERT(!"failed query");
return TrackId();
}
int iUnplayedTracks = 0;
Expand Down Expand Up @@ -640,8 +641,9 @@ TrackId AutoDJCratesDAO::getRandomTrackId() {
oQuery.prepare("SELECT " AUTODJCRATESTABLE_TRACKID " FROM "
AUTODJACTIVETRACKS_TABLE " LIMIT 1 OFFSET ABS (RANDOM() % :active)");
oQuery.bindValue (":active", iActiveTracks);
VERIFY_OR_DEBUG_ASSERT(oQuery.exec()) {
if (!oQuery.exec()) {
LOG_FAILED_QUERY(oQuery);
DEBUG_ASSERT(!"failed query");
return TrackId();
}
if (oQuery.next()) {
Expand Down Expand Up @@ -670,8 +672,9 @@ TrackId AutoDJCratesDAO::getRandomTrackIdFromAutoDj(int percentActive) {
// WHERE autodjrefs > 0;
oQuery.prepare("SELECT COUNT(*) AS count FROM " AUTODJCRATES_TABLE
" WHERE " AUTODJCRATESTABLE_AUTODJREFS " > 0" );
VERIFY_OR_DEBUG_ASSERT(oQuery.exec()) {
if (!oQuery.exec()) {
LOG_FAILED_QUERY(oQuery);
DEBUG_ASSERT(!"failed query");
return TrackId();
}
VERIFY_OR_DEBUG_ASSERT(oQuery.next()) {
Expand Down Expand Up @@ -709,8 +712,9 @@ TrackId AutoDJCratesDAO::getRandomTrackIdFromAutoDj(int percentActive) {
QString::number(m_iAutoDjPlaylistId), // %3
PLAYLISTTABLE_POSITION)); // %4
oQuery.bindValue (":active", iActiveTracks);
VERIFY_OR_DEBUG_ASSERT(oQuery.exec()) {
if (!oQuery.exec()) {
LOG_FAILED_QUERY(oQuery);
DEBUG_ASSERT(!"failed query");
return TrackId();
}
if (oQuery.next()) {
Expand Down Expand Up @@ -1173,8 +1177,9 @@ TrackId AutoDJCratesDAO::getRandomTrackIdFromLibrary(int iPlaylistId) {
" WHERE fs_deleted == 1 )"
" AND mixxx_deleted != 1" );
oQuery.bindValue(":id",iPlaylistId);
VERIFY_OR_DEBUG_ASSERT(oQuery.exec()) {
if (!oQuery.exec()) {
LOG_FAILED_QUERY(oQuery);
DEBUG_ASSERT(!"failed query");
return TrackId();
}
int iTotalTracks = 0;
Expand Down Expand Up @@ -1236,8 +1241,9 @@ TrackId AutoDJCratesDAO::getRandomTrackIdFromLibrary(int iPlaylistId) {
" OFFSET :offset");
oQuery.bindValue(":id", iPlaylistId);
oQuery.bindValue(":offset", offset);
VERIFY_OR_DEBUG_ASSERT(oQuery.exec()) {
if (!oQuery.exec()) {
LOG_FAILED_QUERY(oQuery);
DEBUG_ASSERT(!"failed query");
return TrackId();
}
if (oQuery.next()) {
Expand Down
6 changes: 4 additions & 2 deletions src/library/dao/cuedao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ QList<CuePointer> CueDAO::getCuesForTrack(TrackId trackId) const {
query.isPrepared() &&
!query.hasError());
query.bindValue(":id", trackId.toVariant());
VERIFY_OR_DEBUG_ASSERT(query.execPrepared()) {
if (!query.execPrepared()) {
kLogger.warning()
<< "Failed to load cues of track"
<< trackId;
DEBUG_ASSERT(!"failed query");
return cues;
}
QMap<int, CuePointer> hotCuesByNumber;
Expand Down Expand Up @@ -233,10 +234,11 @@ void CueDAO::saveTrackCues(
query.isPrepared() &&
!query.hasError());
query.bindValue(":track_id", trackId.toVariant());
VERIFY_OR_DEBUG_ASSERT(query.execPrepared()) {
if (!query.execPrepared()) {
kLogger.warning()
<< "Failed to delete orphaned cues of track"
<< trackId;
DEBUG_ASSERT(!"failed query");
return;
}
if (query.numRowsAffected() > 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/library/dao/directorydao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ DirectoryDAO::AddResult DirectoryDAO::addDirectory(
}

for (const auto& oldDir : obsoleteChildDirs) {
VERIFY_OR_DEBUG_ASSERT(RemoveResult::Ok == removeDirectory(oldDir)) {
if (RemoveResult::Ok != removeDirectory(oldDir)) {
kLogger.warning()
<< "Failed to remove obsolete child directory"
<< oldDir;
DEBUG_ASSERT(!"removeDirectory failed");
continue;
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/library/dao/settingsdao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ QString SettingsDAO::getValue(const QString& name, QString defaultValue) const {
query.bindValue(QStringLiteral(":name"), name);
if (query.exec() && query.first()) {
QVariant value = query.value(query.record().indexOf(kColumnValue));
VERIFY_OR_DEBUG_ASSERT(value.isValid()) {
if (!value.isValid()) {
kLogger.warning() << "Invalid value:" << value;
}
else {
DEBUG_ASSERT("!Invalid value");
} else {
return value.toString();
}
}
Expand All @@ -69,10 +69,11 @@ bool SettingsDAO::setValue(const QString& name, const QVariant& value) const {
}
query.bindValue(QStringLiteral(":name"), name);
query.bindValue(QStringLiteral(":value"), value.toString());
VERIFY_OR_DEBUG_ASSERT(query.exec()) {
if (!query.exec()) {
kLogger.warning()
<< "Failed to set" << name << "=" << value
<< query.lastError();
DEBUG_ASSERT(!"Failed query");
return false;
}
return true;
Expand Down
Loading

0 comments on commit 074c938

Please sign in to comment.