From b1d23bb7824ac276f69e35589f33b8ecfeff6831 Mon Sep 17 00:00:00 2001 From: Yavor Georgiev Date: Tue, 11 Jul 2017 17:25:39 +0200 Subject: [PATCH] Realm.open and Realm.openAsync should try/catch opening the realm and pass the error on to the promise and callback respectively so that it can be handled by the caller --- lib/extensions.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/extensions.js b/lib/extensions.js index c8f3d339..8e8e838a 100644 --- a/lib/extensions.js +++ b/lib/extensions.js @@ -49,9 +49,13 @@ module.exports = function(realmConstructor) { reject(error); } - let syncedRealm = new realmConstructor(config); - //FIXME: RN hangs here. Remove when node's makeCallback alternative is implemented - setTimeout(() => { resolve(syncedRealm); }, 1); + try { + let syncedRealm = new this(config); + //FIXME: RN hangs here. Remove when node's makeCallback alternative is implemented + setTimeout(() => { resolve(syncedRealm); }, 1); + } catch (e) { + reject(e); + } }); }); }, @@ -62,9 +66,13 @@ module.exports = function(realmConstructor) { callback(error); } - let syncedRealm = new realmConstructor(config); - //FIXME: RN hangs here. Remove when node's makeCallback alternative is implemented - setTimeout(() => { callback(null, syncedRealm); }, 1); + try { + let syncedRealm = new this(config); + //FIXME: RN hangs here. Remove when node's makeCallback alternative is implemented + setTimeout(() => { callback(null, syncedRealm); }, 1); + } catch (e) { + callback(e); + } }); }, }));