This commit is contained in:
Kenneth Geisshirt 2017-09-21 16:11:27 +02:00
parent d9e50fc41d
commit 3f685c15b8
2 changed files with 20 additions and 32 deletions

View File

@ -253,17 +253,30 @@ public:
};
private:
static void translateSharedGroupOpenException() {
static void translateSharedGroupOpenException(ContextType ctx, realm::Realm::Config config) {
try {
throw;
}
catch (RealmFileException const& ex) {
switch (ex.kind()) {
case RealmFileException::Kind::IncompatibleSyncedRealm: {
throw std::runtime_error("IncompatibleSyncedRealm: "+ ex.path());
switch (ex.kind()) {
case RealmFileException::Kind::IncompatibleSyncedRealm: {
// create an object which is going to be used as exception:
// { message: 'IncompatibleSyncedRealmException', configuration: { path: ... } }
ObjectType configuration = Object::create_empty(ctx);
Object::set_property(ctx, configuration, "path", Value::from_string(ctx, ex.path()));
Object::set_property(ctx, configuration, "schema_mode", Value::from_string(ctx, "readOnly"));
if (!config.encryption_key.empty()) {
Object::set_property(ctx, configuration, "encryption_key", Value::from_binary(ctx, BinaryData(&config.encryption_key[0], 64)));
}
ObjectType object = Object::create_empty(ctx);
Object::set_property(ctx, object, "message", Value::from_string(ctx, "IncompatibleSyncedRealmException"));
Object::set_property(ctx, object, "configuration", configuration);
throw Exception<T>(ctx, object);
}
default:
throw;
}
}
}
}
@ -503,7 +516,7 @@ SharedRealm RealmClass<T>::create_shared_realm(ContextType ctx, realm::Realm::Co
realm = realm::Realm::get_shared_realm(config);
}
catch (...) {
translateSharedGroupOpenException();
translateSharedGroupOpenException(ctx, config);
}
GlobalContextType global_context = Context<T>::get_global_context(ctx);
@ -719,7 +732,7 @@ void RealmClass<T>::wait_for_download_completion(ContextType ctx, FunctionType,
realm = realm::Realm::get_shared_realm(config);
}
catch (...) {
translateSharedGroupOpenException();
translateSharedGroupOpenException(ctx, config);
}
if (auto sync_config = config.sync_config)

View File

@ -318,31 +318,6 @@ struct Exception : public std::runtime_error {
}
};
template<typename T>
struct IncompatibleSyncedRealmException : public std::runtime_error {
using ContextType = typename T::Context;
using ObjectType = typename T::Object;
std::string m_path;
std::vector<char> m_encryption_key;
IncompatibleSyncedRealmException(ContextType ctx, const std::string &path)
: std::runtime_error(std::string("Incompatible Synced Realm")), m_path(path) {}
IncompatibleSyncedRealmException(ContextType ctx, const std::string &path, const std::vector<char> &key)
: std::runtime_error(std::string("Incompatible Synced Realm")), m_path(path), m_encryption_key(key) {}
ObjectType config(ContextType ctx) {
ObjectType configuration = ObjectType::create_empty(ctx);
ObjectType::set_property(ctx, configuration, "path", m_path);
ObjectType::set_property(ctx, configuration, "schema_mode", to_string(ctx, "readOnly"));
if (!m_encryption_key.empty()) {
ObjectType::set_property(ctx, configuration, "encryption_key", to_binary(ctx, m_encryption_key));
}
return configuration;
}
};
template<typename T>
struct ReturnValue {
using ValueType = typename T::Value;