From e4541d0a121805de58fe236b0733853ba1f024fc Mon Sep 17 00:00:00 2001 From: carm Date: Fri, 16 Nov 2012 23:09:34 -0500 Subject: [PATCH] better error message for file io issues --- .../MilkdropPresetFactory/MilkdropPreset.cpp | 25 +++++++++---------- src/libprojectM/PresetFactoryManager.cpp | 4 +-- src/projectM-qt/qprojectm_mainwindow.cpp | 3 ++- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/libprojectM/MilkdropPresetFactory/MilkdropPreset.cpp b/src/libprojectM/MilkdropPresetFactory/MilkdropPreset.cpp index d6acc7b4c..cf27b6fe7 100755 --- a/src/libprojectM/MilkdropPresetFactory/MilkdropPreset.cpp +++ b/src/libprojectM/MilkdropPresetFactory/MilkdropPreset.cpp @@ -37,9 +37,13 @@ #include "fatal.h" #include #include +#include #include "PresetFrameIO.hpp" +#include "PresetFactoryManager.hpp" + + MilkdropPreset::MilkdropPreset(std::istream & in, const std::string & presetName, PresetOutputs & presetOutputs): Preset(presetName), builtinParams(_presetInputs, presetOutputs), @@ -291,15 +295,7 @@ void MilkdropPreset::initialize(const std::string & pathname) if (MILKDROP_PRESET_DEBUG) std::cerr << "[Preset] loading file \"" << pathname << "\"..." << std::endl; - if ((retval = loadPresetFile(pathname)) < 0) - { -if (MILKDROP_PRESET_DEBUG) - std::cerr << "[Preset] failed to load file \"" << - pathname << "\"!" << std::endl; - - /// @bug how should we handle this problem? a well define exception? - throw retval; - } + loadPresetFile(pathname); postloadInitialize(); } @@ -317,7 +313,7 @@ void MilkdropPreset::initialize(std::istream & in) std::cerr << "[Preset] failed to load from stream " << std::endl; /// @bug how should we handle this problem? a well define exception? - throw retval; + throw PresetFactoryException("failed to read from input stream"); } postloadInitialize(); @@ -530,9 +526,12 @@ int MilkdropPreset::loadPresetFile(const std::string & pathname) /* Open the file corresponding to pathname */ std::ifstream fs(pathname.c_str()); if (!fs || fs.eof()) { - if (MILKDROP_PRESET_DEBUG) - std::cerr << "loadPresetFile: loading of file \"" << pathname << "\" failed!\n"; - return PROJECTM_ERROR; + + std::ostringstream oss; + oss << "Problem reading file from path: \"" << pathname << "\""; + + throw PresetFactoryException(oss.str()); + } return readIn(fs); diff --git a/src/libprojectM/PresetFactoryManager.cpp b/src/libprojectM/PresetFactoryManager.cpp index 9a349d2d8..fbc87d680 100644 --- a/src/libprojectM/PresetFactoryManager.cpp +++ b/src/libprojectM/PresetFactoryManager.cpp @@ -96,9 +96,9 @@ std::auto_ptr PresetFactoryManager::allocate(const std::string & url, co PresetFactory & PresetFactoryManager::factory(const std::string & extension) { - if (!_factoryMap.count(extension)) { + if (!extensionHandled(extension)) { std::ostringstream os; - os << "No factory associated with \"" << extension << "\"." << std::endl; + os << "No preset factory associated with \"" << extension << "\"." << std::endl; throw PresetFactoryException(os.str()); } return *_factoryMap[extension]; diff --git a/src/projectM-qt/qprojectm_mainwindow.cpp b/src/projectM-qt/qprojectm_mainwindow.cpp index c01c6c9c7..e7fe4c584 100644 --- a/src/projectM-qt/qprojectm_mainwindow.cpp +++ b/src/projectM-qt/qprojectm_mainwindow.cpp @@ -1305,7 +1305,8 @@ void QProjectM_MainWindow::presetRatingChanged( unsigned int index, int rating, void QProjectM_MainWindow::handleFailedPresetSwitch(const bool isHardCut, const unsigned int index, const QString & message) { - const QString status = QString("Error switch to preset index %1: %2") + qDebug() << "handleFailedPresetSwitch"; + const QString status = QString("Error switching to preset index %1 (%2)") .arg(index).arg(message); statusBar()->showMessage ( tr (status.toStdString().c_str() ) );