Better errors on open fails; remove unused exception.
authorCarl Hetherington <cth@carlh.net>
Thu, 18 Aug 2016 16:02:33 +0000 (17:02 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 18 Aug 2016 16:02:33 +0000 (17:02 +0100)
src/lib/exceptions.cc
src/lib/exceptions.h
src/lib/ffmpeg.cc
src/lib/file_group.cc
src/lib/magick_image_proxy.cc
src/lib/reel_writer.cc
src/lib/util.cc
src/wx/config_dialog.cc

index f07354ca109cb953b61e3f4c53e9eaa21870c5cc..f3e3a999c8a42ed230d88da04657ac9fc5d5984f 100644 (file)
@@ -27,15 +27,8 @@ using std::string;
 using std::runtime_error;
 
 /** @param f File that we were trying to open */
 using std::runtime_error;
 
 /** @param f File that we were trying to open */
-OpenFileError::OpenFileError (boost::filesystem::path f)
-       : FileError (String::compose (_("could not open file %1"), f.string()), f)
-{
-
-}
-
-/** @param f File that we were trying to create */
-CreateFileError::CreateFileError (boost::filesystem::path f)
-       : FileError (String::compose (_("could not create file %1"), f.string()), f)
+OpenFileError::OpenFileError (boost::filesystem::path f, int error)
+       : FileError (String::compose (_("could not open file %1 (%2)"), f.string(), error), f)
 {
 
 }
 {
 
 }
index 31c3f5389fe1685198eceff39ef41f4974c9e504..1a32b5402194ba7357dfa385764c2b4b10d71b48 100644 (file)
@@ -96,20 +96,9 @@ class OpenFileError : public FileError
 {
 public:
        /** @param f File that we were trying to open */
 {
 public:
        /** @param f File that we were trying to open */
-       OpenFileError (boost::filesystem::path f);
+       OpenFileError (boost::filesystem::path f, int error);
 };
 
 };
 
-/** @class CreateFileError.
- *  @brief Indicates that some error occurred when trying to create a file.
- */
-class CreateFileError : public FileError
-{
-public:
-       /** @param f File that we were trying to create */
-       CreateFileError (boost::filesystem::path f);
-};
-
-
 /** @class ReadFileError.
  *  @brief Indicates that some error occurred when trying to read from a file
  */
 /** @class ReadFileError.
  *  @brief Indicates that some error occurred when trying to read from a file
  */
index 1f16514d7496b780b31d1ff5a4002d54c0f63923..f750cfd58118f37819bf6ed23ff5ad687b2ef4fd 100644 (file)
@@ -131,8 +131,9 @@ FFmpeg::setup_general ()
        av_dict_set (&options, "analyzeduration", raw_convert<string> (5 * 60 * 1000000).c_str(), 0);
        av_dict_set (&options, "probesize", raw_convert<string> (5 * 60 * 1000000).c_str(), 0);
 
        av_dict_set (&options, "analyzeduration", raw_convert<string> (5 * 60 * 1000000).c_str(), 0);
        av_dict_set (&options, "probesize", raw_convert<string> (5 * 60 * 1000000).c_str(), 0);
 
-       if (avformat_open_input (&_format_context, 0, 0, &options) < 0) {
-               throw OpenFileError (_ffmpeg_content->path(0).string ());
+       int e = avformat_open_input (&_format_context, 0, 0, &options);
+       if (e < 0) {
+               throw OpenFileError (_ffmpeg_content->path(0).string(), e);
        }
 
        if (avformat_find_stream_info (_format_context, 0) < 0) {
        }
 
        if (avformat_find_stream_info (_format_context, 0) < 0) {
index 548e13fef5cd538d357d541077b3d58fa256ea93..90aa10e28beb9d86aef50479555f378bf524e39d 100644 (file)
@@ -92,7 +92,7 @@ FileGroup::ensure_open_path (size_t p) const
        _current_path = p;
        _current_file = fopen_boost (_paths[_current_path], "rb");
        if (_current_file == 0) {
        _current_path = p;
        _current_file = fopen_boost (_paths[_current_path], "rb");
        if (_current_file == 0) {
-               throw OpenFileError (_paths[_current_path]);
+               throw OpenFileError (_paths[_current_path], errno);
        }
 }
 
        }
 }
 
index d207e0561de2eb33967434a6edc19c7436c75412..25935a8395bdc5e45d0f59fddf3c1ca352084b79 100644 (file)
@@ -43,7 +43,7 @@ MagickImageProxy::MagickImageProxy (boost::filesystem::path path)
        boost::uintmax_t const size = boost::filesystem::file_size (path);
        FILE* f = fopen_boost (path, "rb");
        if (!f) {
        boost::uintmax_t const size = boost::filesystem::file_size (path);
        FILE* f = fopen_boost (path, "rb");
        if (!f) {
-               throw OpenFileError (path);
+               throw OpenFileError (path, errno);
        }
 
        uint8_t* data = new uint8_t[size];
        }
 
        uint8_t* data = new uint8_t[size];
index c1ca2abb1cef2ee37ca6ae41e2a34fbe105c5ccb..6bc879db4b7731ec06ee94faed2d4799cdff3432 100644 (file)
@@ -134,7 +134,7 @@ ReelWriter::write_frame_info (Frame frame, Eyes eyes, dcp::FrameInfo info) const
                file = fopen_boost (info_file, "wb");
        }
        if (!file) {
                file = fopen_boost (info_file, "wb");
        }
        if (!file) {
-               throw OpenFileError (info_file);
+               throw OpenFileError (info_file, errno);
        }
        dcpomatic_fseek (file, frame_info_position (frame, eyes), SEEK_SET);
        fwrite (&info.offset, sizeof (info.offset), 1, file);
        }
        dcpomatic_fseek (file, frame_info_position (frame, eyes), SEEK_SET);
        fwrite (&info.offset, sizeof (info.offset), 1, file);
index 704d4aa9dbb5744e0d1d16af8cb8594fa656ac9c..6a1f2b2848049dd088ebf8b12e1e750d1cfb519d 100644 (file)
@@ -422,7 +422,7 @@ digest_head_tail (vector<boost::filesystem::path> files, boost::uintmax_t size)
        while (i < int64_t (files.size()) && to_do > 0) {
                FILE* f = fopen_boost (files[i], "rb");
                if (!f) {
        while (i < int64_t (files.size()) && to_do > 0) {
                FILE* f = fopen_boost (files[i], "rb");
                if (!f) {
-                       throw OpenFileError (files[i].string());
+                       throw OpenFileError (files[i].string(), errno);
                }
 
                boost::uintmax_t this_time = min (to_do, boost::filesystem::file_size (files[i]));
                }
 
                boost::uintmax_t this_time = min (to_do, boost::filesystem::file_size (files[i]));
@@ -442,7 +442,7 @@ digest_head_tail (vector<boost::filesystem::path> files, boost::uintmax_t size)
        while (i >= 0 && to_do > 0) {
                FILE* f = fopen_boost (files[i], "rb");
                if (!f) {
        while (i >= 0 && to_do > 0) {
                FILE* f = fopen_boost (files[i], "rb");
                if (!f) {
-                       throw OpenFileError (files[i].string());
+                       throw OpenFileError (files[i].string(), errno);
                }
 
                boost::uintmax_t this_time = min (to_do, boost::filesystem::file_size (files[i]));
                }
 
                boost::uintmax_t this_time = min (to_do, boost::filesystem::file_size (files[i]));
index c18cf3c92eae46e788f573182d3772bbb4d42578..13d7e17621a8b003ab5db23264709e518a36be79 100644 (file)
@@ -829,7 +829,7 @@ private:
                if (d->ShowModal () == wxID_OK) {
                        FILE* f = fopen_boost (wx_to_std (d->GetPath ()), "w");
                        if (!f) {
                if (d->ShowModal () == wxID_OK) {
                        FILE* f = fopen_boost (wx_to_std (d->GetPath ()), "w");
                        if (!f) {
-                               throw OpenFileError (wx_to_std (d->GetPath ()));
+                               throw OpenFileError (wx_to_std (d->GetPath ()), errno);
                        }
 
                        string const s = j->certificate (true);
                        }
 
                        string const s = j->certificate (true);
@@ -977,7 +977,7 @@ private:
                if (d->ShowModal () == wxID_OK) {
                        FILE* f = fopen_boost (wx_to_std (d->GetPath ()), "w");
                        if (!f) {
                if (d->ShowModal () == wxID_OK) {
                        FILE* f = fopen_boost (wx_to_std (d->GetPath ()), "w");
                        if (!f) {
-                               throw OpenFileError (wx_to_std (d->GetPath ()));
+                               throw OpenFileError (wx_to_std (d->GetPath ()), errno);
                        }
 
                        string const s = _chain->key().get ();
                        }
 
                        string const s = _chain->key().get ();
@@ -1060,7 +1060,7 @@ private:
                if (d->ShowModal () == wxID_OK) {
                        FILE* f = fopen_boost (wx_to_std (d->GetPath ()), "w");
                        if (!f) {
                if (d->ShowModal () == wxID_OK) {
                        FILE* f = fopen_boost (wx_to_std (d->GetPath ()), "w");
                        if (!f) {
-                               throw OpenFileError (wx_to_std (d->GetPath ()));
+                               throw OpenFileError (wx_to_std (d->GetPath ()), errno);
                        }
 
                        string const s = Config::instance()->decryption_chain()->leaf().certificate (true);
                        }
 
                        string const s = Config::instance()->decryption_chain()->leaf().certificate (true);
@@ -1080,7 +1080,7 @@ private:
                if (d->ShowModal () == wxID_OK) {
                        FILE* f = fopen_boost (wx_to_std (d->GetPath ()), "w");
                        if (!f) {
                if (d->ShowModal () == wxID_OK) {
                        FILE* f = fopen_boost (wx_to_std (d->GetPath ()), "w");
                        if (!f) {
-                               throw OpenFileError (wx_to_std (d->GetPath ()));
+                               throw OpenFileError (wx_to_std (d->GetPath ()), errno);
                        }
 
                        string const s = Config::instance()->decryption_chain()->chain();
                        }
 
                        string const s = Config::instance()->decryption_chain()->chain();