widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #06003
[Merge] lp:~widelands-dev/widelands/file_not_found_message into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/file_not_found_message into lp:widelands.
Commit message:
Added file paths to error messages in exceptions thrown by LayeredFileSystem. Removed unused member variables from filesystem_exceptions.h.
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/file_not_found_message/+merge/285442
More information to help us track down bugs.
Sample error message:
terminate called after throwing an instance of 'FileNotFoundError'
what(): Could not find file: could not find file or directory: shaders/fill_rect.fp
I have tried the following path(s):
/home/me/.widelands/shaders/fill_rect.fp
/home/me/sources/widelands/file_not_found_message/data/shaders/fill_rect.fp
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/file_not_found_message into lp:widelands.
=== modified file 'src/io/filesystem/filesystem_exceptions.h'
--- src/io/filesystem/filesystem_exceptions.h 2014-09-10 13:03:40 +0000
+++ src/io/filesystem/filesystem_exceptions.h 2016-02-09 09:01:00 +0000
@@ -33,15 +33,8 @@
const std::string & message = "problem with file/directory")
:
- std::runtime_error(thrower + ": " + message + ": " + filename),
- m_thrower (thrower),
- m_filename (filename),
- m_message (message)
+ std::runtime_error(thrower + ": " + message + ": " + filename)
{}
-
- std::string m_thrower;
- std::string m_filename;
- std::string m_message;
};
/**
=== modified file 'src/io/filesystem/layered_filesystem.cc'
--- src/io/filesystem/layered_filesystem.cc 2016-01-29 17:06:17 +0000
+++ src/io/filesystem/layered_filesystem.cc 2016-02-09 09:01:00 +0000
@@ -142,7 +142,7 @@
if ((*it)->file_exists(fname))
return (*it)->load(fname, length);
- throw FileNotFoundError("Could not find file", fname);
+ throw FileNotFoundError("LayeredFileSystem: Could not load file", paths_error_message(fname));
}
/**
@@ -159,7 +159,8 @@
if ((*it)->is_writable())
return (*it)->write(fname, data, length);
- throw wexception("LayeredFileSystem: No writable filesystem for %s!", fname.c_str());
+ throw wexception("LayeredFileSystem: No writable filesystem for file: %s",
+ paths_error_message(fname).c_str());
}
/**
@@ -174,7 +175,8 @@
if ((*it)->file_exists(fname))
return (*it)->open_stream_read(fname);
- throw FileNotFoundError("Could not find file", fname);
+ throw FileNotFoundError("LayeredFileSystem: Could not open file for stream read",
+ paths_error_message(fname));
}
/**
@@ -231,8 +233,8 @@
if ((*it)->is_writable() && (*it)->file_exists(dirname))
return (*it)->make_sub_file_system(dirname);
- throw wexception("LayeredFileSystem: unable to create sub filesystem for existing dir: %s",
- dirname.c_str());
+ throw wexception("LayeredFileSystem: unable to create sub filesystem for existing directory: %s",
+ paths_error_message(dirname).c_str());
}
/**
@@ -247,7 +249,8 @@
if ((*it)->is_writable() && !(*it)->file_exists(dirname))
return (*it)->create_sub_file_system(dirname, type);
- throw wexception("LayeredFileSystem: unable to create sub filesystem for new dir: %s", dirname.c_str());
+ throw wexception("LayeredFileSystem: unable to create sub filesystem for new directory: %s",
+ paths_error_message(dirname).c_str());
}
/**
@@ -298,3 +301,17 @@
return (*it)->disk_space();
return 0;
}
+
+std::string LayeredFileSystem::paths_error_message(const std::string& filename) const {
+
+ std::string message = filename + "\nI have tried the following path(s):";
+
+ if (m_home) {
+ message += "\n " + m_home->get_basename() + FileSystem::file_separator() + filename;
+ }
+
+ for (auto it = m_filesystems.rbegin(); it != m_filesystems.rend(); ++it) {
+ message += "\n " + (*it)->get_basename() + FileSystem::file_separator() + filename;
+ }
+ return message;
+}
=== modified file 'src/io/filesystem/layered_filesystem.h'
--- src/io/filesystem/layered_filesystem.h 2016-01-31 15:31:00 +0000
+++ src/io/filesystem/layered_filesystem.h 2016-02-09 09:01:00 +0000
@@ -82,6 +82,9 @@
unsigned long long disk_space() override;
private:
+ /// This is used to assemble an error message for exceptions that includes all file paths
+ std::string paths_error_message(const std::string& filename) const;
+
std::vector<std::unique_ptr<FileSystem>> m_filesystems;
std::unique_ptr<FileSystem> m_home;
};
Follow ups