summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2016-08-18 17:02:33 +0100
committerCarl Hetherington <cth@carlh.net>2016-08-18 17:02:33 +0100
commit513947df0f421c086ac56dff48dfe540b0a380c2 (patch)
tree5fd393d3833a512dffacbeb2bb11eafe4003440e
parent6c16feca6c9b51b4833051eff4b5f6a9e9454a73 (diff)
Better errors on open fails; remove unused exception.
-rw-r--r--src/lib/exceptions.cc11
-rw-r--r--src/lib/exceptions.h13
-rw-r--r--src/lib/ffmpeg.cc5
-rw-r--r--src/lib/file_group.cc2
-rw-r--r--src/lib/magick_image_proxy.cc2
-rw-r--r--src/lib/reel_writer.cc2
-rw-r--r--src/lib/util.cc4
-rw-r--r--src/wx/config_dialog.cc8
8 files changed, 15 insertions, 32 deletions
diff --git a/src/lib/exceptions.cc b/src/lib/exceptions.cc
index f07354ca1..f3e3a999c 100644
--- a/src/lib/exceptions.cc
+++ b/src/lib/exceptions.cc
@@ -27,15 +27,8 @@ using std::string;
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)
{
}
diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h
index 31c3f5389..1a32b5402 100644
--- a/src/lib/exceptions.h
+++ b/src/lib/exceptions.h
@@ -96,20 +96,9 @@ class OpenFileError : public FileError
{
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
*/
diff --git a/src/lib/ffmpeg.cc b/src/lib/ffmpeg.cc
index 1f16514d7..f750cfd58 100644
--- a/src/lib/ffmpeg.cc
+++ b/src/lib/ffmpeg.cc
@@ -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);
- 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) {
diff --git a/src/lib/file_group.cc b/src/lib/file_group.cc
index 548e13fef..90aa10e28 100644
--- a/src/lib/file_group.cc
+++ b/src/lib/file_group.cc
@@ -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) {
- throw OpenFileError (_paths[_current_path]);
+ throw OpenFileError (_paths[_current_path], errno);
}
}
diff --git a/src/lib/magick_image_proxy.cc b/src/lib/magick_image_proxy.cc
index d207e0561..25935a839 100644
--- a/src/lib/magick_image_proxy.cc
+++ b/src/lib/magick_image_proxy.cc
@@ -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) {
- throw OpenFileError (path);
+ throw OpenFileError (path, errno);
}
uint8_t* data = new uint8_t[size];
diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc
index c1ca2abb1..6bc879db4 100644
--- a/src/lib/reel_writer.cc
+++ b/src/lib/reel_writer.cc
@@ -134,7 +134,7 @@ ReelWriter::write_frame_info (Frame frame, Eyes eyes, dcp::FrameInfo info) const
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);
diff --git a/src/lib/util.cc b/src/lib/util.cc
index 704d4aa9d..6a1f2b284 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -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) {
- 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]));
@@ -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) {
- 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]));
diff --git a/src/wx/config_dialog.cc b/src/wx/config_dialog.cc
index c18cf3c92..13d7e1762 100644
--- a/src/wx/config_dialog.cc
+++ b/src/wx/config_dialog.cc
@@ -829,7 +829,7 @@ private:
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);
@@ -977,7 +977,7 @@ private:
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 ();
@@ -1060,7 +1060,7 @@ private:
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);
@@ -1080,7 +1080,7 @@ private:
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();