From 5054bbc1a2e28488f02cc5127c8cdc210ade7be6 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 6 Jun 2016 15:26:13 -0700 Subject: [PATCH] Add the path of the Realm file to the config mismatch exception message --- src/impl/realm_coordinator.cpp | 10 +++++----- src/shared_realm.cpp | 3 +++ src/shared_realm.hpp | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/impl/realm_coordinator.cpp b/src/impl/realm_coordinator.cpp index 2fd0dd0e..f784268f 100644 --- a/src/impl/realm_coordinator.cpp +++ b/src/impl/realm_coordinator.cpp @@ -75,16 +75,16 @@ std::shared_ptr 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 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); } } diff --git a/src/shared_realm.cpp b/src/shared_realm.cpp index 5fd68576..2eccc36e 100644 --- a/src/shared_realm.cpp +++ b/src/shared_realm.cpp @@ -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)) { } diff --git a/src/shared_realm.hpp b/src/shared_realm.hpp index 89766b6f..6ecebf95 100644 --- a/src/shared_realm.hpp +++ b/src/shared_realm.hpp @@ -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 {