Add better logging for file open and write errors

This commit is contained in:
Jonas Kvinge
2021-08-09 23:32:26 +02:00
parent 7d61d8e646
commit f1d3cadb3b
15 changed files with 120 additions and 41 deletions

View File

@@ -388,7 +388,7 @@ void Database::ExecSchemaCommandsFromFile(QSqlDatabase &db, const QString &filen
// Open and read the database schema
QFile schema_file(filename);
if (!schema_file.open(QIODevice::ReadOnly)) {
qFatal("Couldn't open schema file %s", filename.toUtf8().constData());
qFatal("Couldn't open schema file %s for reading: %s", filename.toUtf8().constData(), schema_file.errorString().toUtf8().constData());
return;
}
ExecSchemaCommands(db, QString::fromUtf8(schema_file.readAll()), schema_version, in_transaction);

View File

@@ -281,7 +281,7 @@ SongLoader::Result SongLoader::LoadLocalAsync(const QString &filename) {
// It's a local file, so check if it looks like a playlist. Read the first few bytes.
QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
errors_ << tr("Could not open file %1").arg(filename);
errors_ << tr("Could not open file %1 for reading: %2").arg(filename).arg(file.errorString());
return Error;
}
QByteArray data(file.read(PlaylistParser::kMagicSize));
@@ -312,6 +312,10 @@ SongLoader::Result SongLoader::LoadLocalAsync(const QString &filename) {
}
return Success;
}
else {
errors_ << tr("Could not open CUE file %1 for reading: %2").arg(matching_cue).arg(cue.errorString());
return Error;
}
}
// Assume it's just a normal file
@@ -364,6 +368,9 @@ void SongLoader::LoadPlaylist(ParserBase *parser, const QString &filename) {
songs_ = parser->Load(&file, filename, QFileInfo(filename).path());
file.close();
}
else {
errors_ << tr("Could not open playlist file %1 for reading: %2").arg(filename).arg(file.errorString());
}
}

View File

@@ -58,7 +58,7 @@ void StyleSheetLoader::SetStyleSheet(QWidget *widget, const QString &filename) {
// Load the file
QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
qLog(Error) << "Unable to open" << filename;
qLog(Error) << "Could not open stylesheet file" << filename << "for reading:" << file.errorString();
return;
}
QTextStream stream(&file);

View File

@@ -939,6 +939,9 @@ QByteArray ReadDataFromFile(const QString &filename) {
data = file.readAll();
file.close();
}
else {
qLog(Error) << "Failed to open file" << filename << "for reading:" << file.errorString();
}
return data;
}