Merge pull request #15 from realm/tg-file-error-path

Include the path of the file which actually failed to open in exceptions
This commit is contained in:
Thomas Goyne 2015-11-05 09:35:36 -08:00
commit 62f59d9ae8
2 changed files with 16 additions and 9 deletions

View File

@ -73,18 +73,22 @@ Realm::Realm(Config config)
} }
} }
catch (util::File::PermissionDenied const& ex) { catch (util::File::PermissionDenied const& ex) {
throw RealmFileException(RealmFileException::Kind::PermissionDenied, "Unable to open a realm at path '" + m_config.path + throw RealmFileException(RealmFileException::Kind::PermissionDenied, ex.get_path(),
"'. Please use a path where your app has " + (m_config.read_only ? "read" : "read-write") + " permissions."); "Unable to open a realm at path '" + ex.get_path() +
"'. Please use a path where your app has " + (m_config.read_only ? "read" : "read-write") + " permissions.");
} }
catch (util::File::Exists const& ex) { catch (util::File::Exists const& ex) {
throw RealmFileException(RealmFileException::Kind::Exists, "Unable to open a realm at path '" + m_config.path + "'"); throw RealmFileException(RealmFileException::Kind::Exists, ex.get_path(),
"File at path '" + ex.get_path() + "' already exists.");
} }
catch (util::File::AccessError const& ex) { catch (util::File::AccessError const& ex) {
throw RealmFileException(RealmFileException::Kind::AccessError, "Unable to open a realm at path '" + m_config.path + "'"); throw RealmFileException(RealmFileException::Kind::AccessError, ex.get_path(),
"Unable to open a realm at path '" + ex.get_path() + "'");
} }
catch (IncompatibleLockFile const&) { catch (IncompatibleLockFile const& ex) {
throw RealmFileException(RealmFileException::Kind::IncompatibleLockFile, "Realm file is currently open in another process " throw RealmFileException(RealmFileException::Kind::IncompatibleLockFile, m_config.path,
"which cannot share access with this process. All processes sharing a single file must be the same architecture."); "Realm file is currently open in another process "
"which cannot share access with this process. All processes sharing a single file must be the same architecture.");
} }
} }

View File

@ -151,7 +151,7 @@ namespace realm {
/** Thrown if the user does not have permission to open or create /** Thrown if the user does not have permission to open or create
the specified file in the specified access mode when the realm is opened. */ the specified file in the specified access mode when the realm is opened. */
PermissionDenied, PermissionDenied,
/** Thrown if no_create was specified and the file did already exist when the realm is opened. */ /** Thrown if create_Always was specified and the file did already exist when the realm is opened. */
Exists, Exists,
/** Thrown if no_create was specified and the file was not found when the realm is opened. */ /** Thrown if no_create was specified and the file was not found when the realm is opened. */
NotFound, NotFound,
@ -160,11 +160,14 @@ namespace realm {
architecture mismatch. */ architecture mismatch. */
IncompatibleLockFile, IncompatibleLockFile,
}; };
RealmFileException(Kind kind, std::string message) : std::runtime_error(message), m_kind(kind) {} RealmFileException(Kind kind, std::string path, std::string message) :
std::runtime_error(std::move(message)), m_kind(kind), m_path(std::move(path)) {}
Kind kind() const { return m_kind; } Kind kind() const { return m_kind; }
const std::string& path() const { return m_path; }
private: private:
Kind m_kind; Kind m_kind;
std::string m_path;
}; };
class MismatchedConfigException : public std::runtime_error class MismatchedConfigException : public std::runtime_error