Creating a proper IncompatibleSyncedRealmError class.
This commit is contained in:
parent
4b2acf3b79
commit
39fe8c6280
|
@ -87,8 +87,8 @@ class Realm {
|
||||||
* `config.schemaVersion` is incremented, in which case the Realm will be automatically
|
* `config.schemaVersion` is incremented, in which case the Realm will be automatically
|
||||||
* migrated to use the new schema.
|
* migrated to use the new schema.
|
||||||
* @param {Realm~Configuration} [config] - **Required** when first creating the Realm.
|
* @param {Realm~Configuration} [config] - **Required** when first creating the Realm.
|
||||||
* @throws {Error} If anything in the provided `config` is invalid or migration from RMP
|
* @throws {Error} If anything in the provided `config` is invalid.
|
||||||
* version 1 to 2 is not possible.
|
* @throws IncompatibleSyncedRealmError} if migration from RMP version 1 to 2 is not possible.
|
||||||
*/
|
*/
|
||||||
constructor(config) {}
|
constructor(config) {}
|
||||||
|
|
||||||
|
@ -106,8 +106,8 @@ class Realm {
|
||||||
* @param {Realm~Configuration} config
|
* @param {Realm~Configuration} config
|
||||||
* @param {callback(error, realm)} - will be called when the realm is ready.
|
* @param {callback(error, realm)} - will be called when the realm is ready.
|
||||||
* @param {callback(transferred, transferable)} [progressCallback] - an optional callback for download progress notifications
|
* @param {callback(transferred, transferable)} [progressCallback] - an optional callback for download progress notifications
|
||||||
* @throws {Error} If anything in the provided `config` is invalid or migration from RMP
|
* @throws {Error} If anything in the provided `config` is invalid
|
||||||
* version 1 to 2 is not possible.
|
* @throws {IncompatibleSyncedRealmError} if migration from RMP version 1 to 2 is not possible
|
||||||
*/
|
*/
|
||||||
static openAsync(config, callback, progressCallback) {}
|
static openAsync(config, callback, progressCallback) {}
|
||||||
|
|
||||||
|
|
12
docs/sync.js
12
docs/sync.js
|
@ -132,6 +132,18 @@ class AuthError extends Error {
|
||||||
get type() {}
|
get type() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class that describes error in migration of a Realm from Realm Mobile Platform v1.x to v2.x
|
||||||
|
* @memberof Realm.Sync
|
||||||
|
*/
|
||||||
|
class IncompatibleSyncedRealmError extends Error {
|
||||||
|
/**
|
||||||
|
* The {Realm~Configuration} of the backed up Realm.
|
||||||
|
* @type {Realm~Configuration}
|
||||||
|
*/
|
||||||
|
get configuration() {}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for logging in and managing Sync users.
|
* Class for logging in and managing Sync users.
|
||||||
* @memberof Realm.Sync
|
* @memberof Realm.Sync
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
function AuthError(problem) {
|
function AuthError(problem) {
|
||||||
const error = Error.call(this, problem.title);
|
const error = Error.call(this, problem.title);
|
||||||
|
|
||||||
this.name = 'AuthError';
|
this.name = 'AuthError';
|
||||||
this.message = error.message;
|
this.message = error.message;
|
||||||
this.stack = error.stack;
|
this.stack = error.stack;
|
||||||
|
@ -32,3 +32,20 @@ AuthError.__proto__ = Error;
|
||||||
AuthError.prototype.__proto__ = Error.prototype;
|
AuthError.prototype.__proto__ = Error.prototype;
|
||||||
|
|
||||||
exports['AuthError'] = AuthError;
|
exports['AuthError'] = AuthError;
|
||||||
|
|
||||||
|
|
||||||
|
function IncompatibleSyncedRealmError(problem, configuration) {
|
||||||
|
const error = Error.call(this, problem.title);
|
||||||
|
|
||||||
|
this.name = 'IncompatibleSyncedRealmError';
|
||||||
|
this.message = error.message;
|
||||||
|
this.stack = error.stack;
|
||||||
|
this.configuration = configuration;
|
||||||
|
|
||||||
|
Object.assign(this, problem);
|
||||||
|
}
|
||||||
|
|
||||||
|
IncompatibleSyncedRealmError.__proto__ = Error;
|
||||||
|
IncompatibleSyncedRealmError.prototype.__proto__ = Error.prototype;
|
||||||
|
|
||||||
|
exports['IncompatibleSyncedRealmError'] = IncompatibleSyncedRealmError;
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const IncompatibleSyncedRealmError = require('./Errors').IncompatibleSyncedRealmError;
|
||||||
|
|
||||||
let getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors || function(obj) {
|
let getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors || function(obj) {
|
||||||
return Object.getOwnPropertyNames(obj).reduce(function (descriptors, name) {
|
return Object.getOwnPropertyNames(obj).reduce(function (descriptors, name) {
|
||||||
descriptors[name] = Object.getOwnPropertyDescriptor(obj, name);
|
descriptors[name] = Object.getOwnPropertyDescriptor(obj, name);
|
||||||
|
@ -59,6 +61,9 @@ module.exports = function(realmConstructor) {
|
||||||
//FIXME: RN hangs here. Remove when node's makeCallback alternative is implemented
|
//FIXME: RN hangs here. Remove when node's makeCallback alternative is implemented
|
||||||
setTimeout(() => { resolve(syncedRealm); }, 1);
|
setTimeout(() => { resolve(syncedRealm); }, 1);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (e.message === 'IncompatibleSyncedRealm') {
|
||||||
|
reject(new IncompatibleSyncedRealmError(e.configuration));
|
||||||
|
}
|
||||||
reject(e);
|
reject(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,6 +101,9 @@ module.exports = function(realmConstructor) {
|
||||||
//FIXME: RN hangs here. Remove when node's makeCallback alternative is implemented
|
//FIXME: RN hangs here. Remove when node's makeCallback alternative is implemented
|
||||||
setTimeout(() => { callback(null, syncedRealm); }, 1);
|
setTimeout(() => { callback(null, syncedRealm); }, 1);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (e.message === 'IncompatibleSyncedRealm') {
|
||||||
|
throw new IncompatibleSyncedRealmError(e.configuration);
|
||||||
|
}
|
||||||
setTimeout(() => { callback(e); }, 1);
|
setTimeout(() => { callback(e); }, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,7 +271,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectType object = Object::create_empty(ctx);
|
ObjectType object = Object::create_empty(ctx);
|
||||||
Object::set_property(ctx, object, "message", Value::from_string(ctx, "IncompatibleSyncedRealmException"));
|
Object::set_property(ctx, object, "message", Value::from_string(ctx, "IncompatibleSyncedRealm"));
|
||||||
Object::set_property(ctx, object, "configuration", configuration);
|
Object::set_property(ctx, object, "configuration", configuration);
|
||||||
throw Exception<T>(ctx, object);
|
throw Exception<T>(ctx, object);
|
||||||
}
|
}
|
||||||
|
|
|
@ -469,7 +469,7 @@ module.exports = {
|
||||||
const realm = new Realm(config);
|
const realm = new Realm(config);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
if (e.message === 'IncompatibleSyncedRealmException') {
|
if (e instanceof IncompatibleSyncedRealmError) {
|
||||||
const backupRealm = new Realm(e.configuration);
|
const backupRealm = new Realm(e.configuration);
|
||||||
TestCase.assertNotEqual(backupRealm.objects('Person').length, 0);
|
TestCase.assertNotEqual(backupRealm.objects('Person').length, 0);
|
||||||
resolve();
|
resolve();
|
||||||
|
|
Loading…
Reference in New Issue