Skip to content

Commit

Permalink
Merge pull request #15 from realm/tg-file-error-path
Browse files Browse the repository at this point in the history
Include the path of the file which actually failed to open in exceptions
  • Loading branch information
tgoyne committed Nov 5, 2015
2 parents 271432b + b93e5ce commit 62f59d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
18 changes: 11 additions & 7 deletions shared_realm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,22 @@ Realm::Realm(Config config)
}
}
catch (util::File::PermissionDenied const& ex) {
throw RealmFileException(RealmFileException::Kind::PermissionDenied, "Unable to open a realm at path '" + m_config.path +
"'. Please use a path where your app has " + (m_config.read_only ? "read" : "read-write") + " permissions.");
throw RealmFileException(RealmFileException::Kind::PermissionDenied, ex.get_path(),
"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) {
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) {
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&) {
throw RealmFileException(RealmFileException::Kind::IncompatibleLockFile, "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.");
catch (IncompatibleLockFile const& ex) {
throw RealmFileException(RealmFileException::Kind::IncompatibleLockFile, m_config.path,
"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.");
}
}

Expand Down
7 changes: 5 additions & 2 deletions shared_realm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ namespace realm {
/** 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. */
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,
/** Thrown if no_create was specified and the file was not found when the realm is opened. */
NotFound,
Expand All @@ -160,11 +160,14 @@ namespace realm {
architecture mismatch. */
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; }
const std::string& path() const { return m_path; }

private:
Kind m_kind;
std::string m_path;
};

class MismatchedConfigException : public std::runtime_error
Expand Down

0 comments on commit 62f59d9

Please sign in to comment.