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; QString destFile = dst + QDir::separator() + f;
if (!QFile::exists(destFile)) { 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 // TODO: Since copyPath is only used by loaders, it should
// build the list of files first, and then update the progress bar // build the list of files first, and then update the progress bar
// while copying. // while copying.

View File

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

View File

@ -142,7 +142,8 @@ bool Machine::saveSessionInfo()
QString filename = getDataPath() + "Sessions.info"; QString filename = getDataPath() + "Sessions.info";
QFile file(filename); QFile file(filename);
if (!file.open(QFile::WriteOnly)) { 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; return false;
} }
@ -898,7 +899,8 @@ bool Machine::LoadSummary(ProgressDialog * progress)
QApplication::processEvents(); QApplication::processEvents();
if (!file.open(QIODevice::ReadOnly)) { 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; return false;
} }
@ -1113,7 +1115,9 @@ bool Machine::SaveSummaryCache()
QFile file(filename + ".gz"); 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); file.write(data);
return true; return true;

View File

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

View File

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

View File

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

View File

@ -317,7 +317,8 @@ bool Session::StoreSummary()
dir.mkpath(s_machine->getSummariesPath()); dir.mkpath(s_machine->getSummariesPath());
if (!file.open(QIODevice::WriteOnly)) { 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; return false;
} }
} }
@ -395,7 +396,7 @@ bool Session::LoadSummary()
QFile file(filename); QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) { 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; return false;
} }
@ -669,7 +670,10 @@ bool Session::StoreEvents()
QString filename = path+QString().sprintf("%08lx.001", s_session); QString filename = path+QString().sprintf("%08lx.001", s_session);
QFile file(filename); 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; QByteArray headerbytes;
QDataStream header(&headerbytes, QIODevice::WriteOnly); QDataStream header(&headerbytes, QIODevice::WriteOnly);
@ -813,7 +817,8 @@ bool Session::LoadEvents(QString filename)
QFile file(filename); QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) { 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; return false;
} }

View File

@ -84,7 +84,8 @@ QString AboutDialog::getAbout()
if (clfile.open(QIODevice::ReadOnly)) { if (clfile.open(QIODevice::ReadOnly)) {
text = clfile.readAll(); text = clfile.readAll();
} else } 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; return text;
} }
@ -96,6 +97,8 @@ QString AboutDialog::getCredits()
QString text = tr("Sorry, could not locate Credits file."); QString text = tr("Sorry, could not locate Credits file.");
if (clfile.open(QIODevice::ReadOnly)) { if (clfile.open(QIODevice::ReadOnly)) {
text = clfile.readAll(); text = clfile.readAll();
} else {
qWarning() << "Could not open" << creditsFile << "for reading, error code" << clfile.error() << clfile.errorString();
} }
return text; return text;
@ -111,6 +114,8 @@ QString AboutDialog::getRelnotes()
//QTextStream ts(&clfile); //QTextStream ts(&clfile);
changeLog = clfile.readAll(); changeLog = clfile.readAll();
} }
else
qWarning() << "Could not open" << relNotesFile << "for reading, error code" << clfile.error() << clfile.errorString();
QString text = "<html>" QString text = "<html>"
"<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head>" "<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() void ExportCSV::on_exportButton_clicked()
{ {
QFile file(ui->filenameEdit->text()); 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; QString header;
const QString sep = ","; const QString sep = ",";
const QString newline = "\n"; const QString newline = "\n";

View File

@ -95,7 +95,7 @@ void LogThread::logToFile()
} }
QString debugLog = GetLogDir() + "/debug.txt"; 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(); strlock.lock();
m_logFile = new QFile(debugLog); m_logFile = new QFile(debugLog);

View File

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

View File

@ -39,7 +39,8 @@ bool ZipFile::Open(const QString & filepath)
m_file.setFileName(filepath); m_file.setFileName(filepath);
bool ok = m_file.open(QIODevice::WriteOnly); bool ok = m_file.open(QIODevice::WriteOnly);
if (!ok) { 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; return false;
} }
ok = zip_open(m_ctx, m_file); ok = zip_open(m_ctx, m_file);