Include the path of the file which actually failed to open in exceptions
When the user (or our tests...) do dumb things it's sometimes not actually the realm file itself that failed to open.
This commit is contained in:
parent
271432bd1c
commit
b93e5cedff
|
@ -73,17 +73,21 @@ 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 +
|
||||
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 "
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue