Merge pull request #86 from realm/tg/config-error-path

Add the path of the Realm file to the config mismatch exception message
This commit is contained in:
Thomas Goyne 2016-06-06 16:05:45 -07:00
commit 789e7d3c1b
3 changed files with 9 additions and 6 deletions

View File

@ -75,16 +75,16 @@ std::shared_ptr<Realm> RealmCoordinator::get_realm(Realm::Config config)
}
else {
if (m_config.read_only != config.read_only) {
throw MismatchedConfigException("Realm at path already opened with different read permissions.");
throw MismatchedConfigException("Realm at path '%1' already opened with different read permissions.", config.path);
}
if (m_config.in_memory != config.in_memory) {
throw MismatchedConfigException("Realm at path already opened with different inMemory settings.");
throw MismatchedConfigException("Realm at path '%1' already opened with different inMemory settings.", config.path);
}
if (m_config.encryption_key != config.encryption_key) {
throw MismatchedConfigException("Realm at path already opened with a different encryption key.");
throw MismatchedConfigException("Realm at path '%1' already opened with a different encryption key.", config.path);
}
if (m_config.schema_version != config.schema_version && config.schema_version != ObjectStore::NotVersioned) {
throw MismatchedConfigException("Realm at path already opened with different schema version.");
throw MismatchedConfigException("Realm at path '%1' already opened with different schema version.", config.path);
}
// FIXME: verify that schema is compatible
// Needs to verify that all tables present in both are identical, and
@ -93,7 +93,7 @@ std::shared_ptr<Realm> RealmCoordinator::get_realm(Realm::Config config)
// Public API currently doesn't make it possible to have non-matching
// schemata so it's not a huge issue
if ((false) && m_config.schema != config.schema) {
throw MismatchedConfigException("Realm at path already opened with different schema");
throw MismatchedConfigException("Realm at path '%1' already opened with different schema", config.path);
}
}

View File

@ -492,3 +492,6 @@ void Realm::close()
m_binding_context = nullptr;
m_coordinator = nullptr;
}
MismatchedConfigException::MismatchedConfigException(StringData message, StringData path)
: std::runtime_error(util::format(message.data(), path)) { }

View File

@ -217,7 +217,7 @@ namespace realm {
class MismatchedConfigException : public std::runtime_error {
public:
MismatchedConfigException(std::string message) : std::runtime_error(move(message)) {}
MismatchedConfigException(StringData message, StringData path);
};
class InvalidTransactionException : public std::runtime_error {