Skip to content

Commit e4541d0

Browse files
author
carm
committed
better error message for file io issues
1 parent 3e3624e commit e4541d0

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/libprojectM/MilkdropPresetFactory/MilkdropPreset.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@
3737
#include "fatal.h"
3838
#include <iostream>
3939
#include <fstream>
40+
#include <sstream>
4041

4142
#include "PresetFrameIO.hpp"
4243

44+
#include "PresetFactoryManager.hpp"
45+
46+
4347
MilkdropPreset::MilkdropPreset(std::istream & in, const std::string & presetName, PresetOutputs & presetOutputs):
4448
Preset(presetName),
4549
builtinParams(_presetInputs, presetOutputs),
@@ -291,15 +295,7 @@ void MilkdropPreset::initialize(const std::string & pathname)
291295
if (MILKDROP_PRESET_DEBUG)
292296
std::cerr << "[Preset] loading file \"" << pathname << "\"..." << std::endl;
293297

294-
if ((retval = loadPresetFile(pathname)) < 0)
295-
{
296-
if (MILKDROP_PRESET_DEBUG)
297-
std::cerr << "[Preset] failed to load file \"" <<
298-
pathname << "\"!" << std::endl;
299-
300-
/// @bug how should we handle this problem? a well define exception?
301-
throw retval;
302-
}
298+
loadPresetFile(pathname);
303299

304300
postloadInitialize();
305301
}
@@ -317,7 +313,7 @@ void MilkdropPreset::initialize(std::istream & in)
317313
std::cerr << "[Preset] failed to load from stream " << std::endl;
318314

319315
/// @bug how should we handle this problem? a well define exception?
320-
throw retval;
316+
throw PresetFactoryException("failed to read from input stream");
321317
}
322318

323319
postloadInitialize();
@@ -530,9 +526,12 @@ int MilkdropPreset::loadPresetFile(const std::string & pathname)
530526
/* Open the file corresponding to pathname */
531527
std::ifstream fs(pathname.c_str());
532528
if (!fs || fs.eof()) {
533-
if (MILKDROP_PRESET_DEBUG)
534-
std::cerr << "loadPresetFile: loading of file \"" << pathname << "\" failed!\n";
535-
return PROJECTM_ERROR;
529+
530+
std::ostringstream oss;
531+
oss << "Problem reading file from path: \"" << pathname << "\"";
532+
533+
throw PresetFactoryException(oss.str());
534+
536535
}
537536

538537
return readIn(fs);

src/libprojectM/PresetFactoryManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ std::auto_ptr<Preset> PresetFactoryManager::allocate(const std::string & url, co
9696

9797
PresetFactory & PresetFactoryManager::factory(const std::string & extension) {
9898

99-
if (!_factoryMap.count(extension)) {
99+
if (!extensionHandled(extension)) {
100100
std::ostringstream os;
101-
os << "No factory associated with \"" << extension << "\"." << std::endl;
101+
os << "No preset factory associated with \"" << extension << "\"." << std::endl;
102102
throw PresetFactoryException(os.str());
103103
}
104104
return *_factoryMap[extension];

src/projectM-qt/qprojectm_mainwindow.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,8 @@ void QProjectM_MainWindow::presetRatingChanged( unsigned int index, int rating,
13051305
void QProjectM_MainWindow::handleFailedPresetSwitch(const bool isHardCut, const unsigned int index,
13061306
const QString & message) {
13071307

1308-
const QString status = QString("Error switch to preset index %1: %2")
1308+
qDebug() << "handleFailedPresetSwitch";
1309+
const QString status = QString("Error switching to preset index %1 (%2)")
13091310
.arg(index).arg(message);
13101311

13111312
statusBar()->showMessage ( tr (status.toStdString().c_str() ) );

0 commit comments

Comments
 (0)