File error checking Phase I: check all file.open() operations are successful.

file.open() checked everywhere except in loaders.
    qWarning() message written to debug log, with error number and text.
    We may want to exit OSCAR with a message in many situations, but that is not implemented yet.
    Set number of debug logs to be kept for Release version to 4.
This commit is contained in:
Guy Scharf 2020-08-09 10:33:04 -07:00
parent 4885abf76a
commit 1aba6e4e51
12 changed files with 54 additions and 19 deletions

View File

@ -418,7 +418,9 @@ void copyPath(QString src, QString dst)
QString destFile = dst + QDir::separator() + f;
if (!QFile::exists(destFile)) {
QFile::copy(srcFile, destFile);
if (!QFile::copy(srcFile, destFile)) {
qWarning() << "Could not copy" << srcFile << "to" << destFile;
}
// TODO: Since copyPath is only used by loaders, it should
// build the list of files first, and then update the progress bar
// while copying.

View File

@ -296,6 +296,7 @@ void BackupJournal(QString filename)
QFile file(filename);
if (!file.open(QIODevice::WriteOnly)) {
qWarning() << "Couldn't open journal file" << filename << "error code" << file.error() << file.errorString();
return;
}

View File

@ -142,7 +142,8 @@ bool Machine::saveSessionInfo()
QString filename = getDataPath() + "Sessions.info";
QFile file(filename);
if (!file.open(QFile::WriteOnly)) {
qDebug() << "Couldn't open" << filename << "for writing";
// qDebug() << "Couldn't open" << filename << "for writing";
qWarning() << "Couldn't open" << filename << "for writing, error code" << file.error() << file.errorString();
return false;
}
@ -898,7 +899,8 @@ bool Machine::LoadSummary(ProgressDialog * progress)
QApplication::processEvents();
if (!file.open(QIODevice::ReadOnly)) {
qWarning() << "Could not open" << filename;
// qWarning() << "Could not open" << filename;
qWarning() << "Could not open" << filename << "for reading, error code" << file.error() << file.errorString();
return false;
}
@ -1113,7 +1115,9 @@ bool Machine::SaveSummaryCache()
QFile file(filename + ".gz");
file.open(QFile::WriteOnly);
if (!file.open(QFile::WriteOnly)) {
qWarning() << "Couldn't open summary cache" << filename << "for writing, error code" << file.error() << file.errorString();
}
file.write(data);
return true;

View File

@ -177,7 +177,8 @@ bool Preferences::Open(QString filename)
qDebug() << "Opening " << p_filename.toLocal8Bit().data();
if (!file.open(QIODevice::ReadOnly)) {
qWarning() << "Could not open" << p_filename.toLocal8Bit().data() << " Error: " << file.error();
// qWarning() << "Could not open" << p_filename.toLocal8Bit().data() << " Error: " << file.error();
qWarning() << "Could not open preferences file" << filename << "for reading, error code" << file.error() << file.errorString();
return false;
}
@ -315,11 +316,14 @@ bool Preferences::Open(QString filename)
// Don't do anything if machines.xml already exists.. the user ran the old version!
if (!file.exists()) {
file.open(QFile::WriteOnly);
if (!file.open(QFile::WriteOnly)) {
qWarning() << "Could not open" << filename << "for writing, error code" << file.error() << file.errorString();
} else {
file.write(doc.toByteArray());
file.close();
}
}
}
return true;
}
@ -359,6 +363,7 @@ bool Preferences::Save(QString filename)
QFile file(p_filename);
if (!file.open(QIODevice::WriteOnly)) {
qWarning() << "Could not open" << p_filename << "for writing, error code" << file.error() << file.errorString();
return false;
}

View File

@ -169,7 +169,8 @@ bool Profile::OpenMachines()
QString filename = p_path+"machines.xml";
QFile file(filename);
if (!file.open(QFile::ReadOnly)) {
qWarning() << "Could not open" << filename.toLocal8Bit().data();
// qWarning() << "Could not open" << filename.toLocal8Bit().data();
qWarning() << "Could not open" << filename.toLocal8Bit().data() << "for reading, error code" << file.error() << file.errorString();
return false;
}
QDomDocument doc("machines.xml");
@ -318,6 +319,7 @@ bool Profile::StoreMachines()
QString filename = p_path+"machines.xml";
QFile file(filename);
if (!file.open(QFile::WriteOnly)) {
qWarning() << "Could not open" << filename << "for writing, error code" << file.error() << file.errorString();
return false;
}
file.write(doc.toByteArray());
@ -1068,7 +1070,10 @@ void saveProfileList()
}
QFile file(filename);
file.open(QFile::WriteOnly);
if (!file.open(QFile::WriteOnly)) {
qWarning() << "Could not open" << filename << "for writing, error code" << file.error() << file.errorString();
return;
}
file.write(doc.toByteArray());

View File

@ -446,7 +446,8 @@ bool ChannelList::Load(QString filename)
qDebug() << "Opening " << filename;
if (!file.open(QIODevice::ReadOnly)) {
qWarning() << "Could not open" << filename;
// qWarning() << "Could not open" << filename;
qWarning() << "Could not open" << filename << "for reading, error code" << file.error() << file.errorString();
return false;
}
@ -715,6 +716,7 @@ bool ChannelList::Save(QString filename)
QFile file(filename);
if (!file.open(QIODevice::WriteOnly)) {
qWarning() << "Could not open" << filename << "for writing, error code" << file.error() << file.errorString();
return false;
}

View File

@ -317,7 +317,8 @@ bool Session::StoreSummary()
dir.mkpath(s_machine->getSummariesPath());
if (!file.open(QIODevice::WriteOnly)) {
qDebug() << "Summary open for writing failed";
// qWarning() << "Summary open for writing failed" << "error code" << file.error() << file.errorString();
qWarning() << "Could not open summary" << filename << "for writing, error code" << file.error() << file.errorString();
return false;
}
}
@ -395,7 +396,7 @@ bool Session::LoadSummary()
QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
qDebug() << "Couldn't open summary file" << filename;
qWarning() << "Could not open summary file" << filename << "for reading, error code" << file.error() << file.errorString();
return false;
}
@ -669,7 +670,10 @@ bool Session::StoreEvents()
QString filename = path+QString().sprintf("%08lx.001", s_session);
QFile file(filename);
file.open(QIODevice::WriteOnly);
if (!file.open(QIODevice::WriteOnly)) {
qWarning() << "Could not open events file" << filename << "for writing, error code" << file.error() << file.errorString();
return false;
}
QByteArray headerbytes;
QDataStream header(&headerbytes, QIODevice::WriteOnly);
@ -813,7 +817,8 @@ bool Session::LoadEvents(QString filename)
QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
qDebug() << "No Event/Waveform data available for" << s_session;
// qDebug() << "No Event/Waveform data available for" << s_session;
qWarning() << "No Event/Waveform data available for" << s_session << "filename" << filename << "error code" << file.error() << file.errorString();
return false;
}

View File

@ -84,7 +84,8 @@ QString AboutDialog::getAbout()
if (clfile.open(QIODevice::ReadOnly)) {
text = clfile.readAll();
} else
qDebug() << "Failed to open About file";
qWarning() << "Could not open" << aboutFile << "for reading, error code" << clfile.error() << clfile.errorString();
// qDebug() << "Failed to open About file";
return text;
}
@ -96,6 +97,8 @@ QString AboutDialog::getCredits()
QString text = tr("Sorry, could not locate Credits file.");
if (clfile.open(QIODevice::ReadOnly)) {
text = clfile.readAll();
} else {
qWarning() << "Could not open" << creditsFile << "for reading, error code" << clfile.error() << clfile.errorString();
}
return text;
@ -111,6 +114,8 @@ QString AboutDialog::getRelnotes()
//QTextStream ts(&clfile);
changeLog = clfile.readAll();
}
else
qWarning() << "Could not open" << relNotesFile << "for reading, error code" << clfile.error() << clfile.errorString();
QString text = "<html>"
"<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head>"

View File

@ -145,7 +145,10 @@ void ExportCSV::on_quickRangeCombo_activated(const QString &arg1)
void ExportCSV::on_exportButton_clicked()
{
QFile file(ui->filenameEdit->text());
file.open(QFile::WriteOnly);
if (!file.open(QFile::WriteOnly)) {
qWarning() << "Could not open" << ui->filenameEdit->text() << "for writing, error code" << file.error() << file.errorString();
return;
}
QString header;
const QString sep = ",";
const QString newline = "\n";

View File

@ -95,7 +95,7 @@ void LogThread::logToFile()
}
QString debugLog = GetLogDir() + "/debug.txt";
rotateLogs(debugLog); // keep a limited set of previous logs
rotateLogs(debugLog, 4); // keep a limited set of previous logs
strlock.lock();
m_logFile = new QFile(debugLog);

View File

@ -118,6 +118,7 @@ void Statistics::loadRXChanges()
QString path = p_profile->Get("{" + STR_GEN_DataFolder + "}/RXChanges.cache" );
QFile file(path);
if (!file.open(QFile::ReadOnly)) {
qWarning() << "Could not open" << path << "for reading, error code" << file.error() << file.errorString();
return;
}
QDataStream in(&file);
@ -143,6 +144,7 @@ void Statistics::saveRXChanges()
QString path = p_profile->Get("{" + STR_GEN_DataFolder + "}/RXChanges.cache" );
QFile file(path);
if (!file.open(QFile::WriteOnly)) {
qWarning() << "Could not open" << path << "for writing, error code" << file.error() << file.errorString();
return;
}
QDataStream out(&file);

View File

@ -39,7 +39,8 @@ bool ZipFile::Open(const QString & filepath)
m_file.setFileName(filepath);
bool ok = m_file.open(QIODevice::WriteOnly);
if (!ok) {
qWarning() << "unable to open" << m_file.fileName();
qWarning() << "Could not open" << m_file.fileName() << "for writing, error code" << m_file.error() << m_file.errorString();
// qWarning() << "unable to open" << m_file.fileName();
return false;
}
ok = zip_open(m_ctx, m_file);