Cannot open Realm database in React Native using Realm Studio - react-native

I create, open and write on a realm database using following functions:
To load the database or to create a new one I am using:
let realm = new Realm({
path: 'UserDatabase.realm',
schema: [
{
name: 'user_details',
properties: {
user_id: {type: 'int', default: 0},
user_name: 'string',
user_contact: 'string',
user_address: 'string',
},
},
],
});
Write some data:
let realmWrite = () => {
if (realm === null || realm === undefined) {
console.error('realm is:' + realm);
} else {
realm.write(() => {
var ID = 1;
realm.create('user_details', {
user_id: ID,
user_name: 'username' + ID,
user_contact: 'contact',
user_address: `asd${ID}#asd.asd`,
});
});
}
};
Apparently writing data doesn't work, so I try to open the database using Realm Studio and I get following errors:
CLASSES
Unable to open a realm at path '/Users/shinigami/Library/Developer/CoreSimulator/Devices/DEB97125-E440-4AAA-9326-7E2B8D29F158/data/Containers/Data/Application/F2B137EF-F864-454D-A622-184C95C39EEE/Documents/UserDatabase.realm': Invalid top array (ref: 1080, size: 11)
Exception backtrace:
0 .io.realm.realm-studio.SwVRf2 0x000000010dcfe581 _ZN5realm15InvalidDatabaseC2ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_ + 49
1 .io.realm.realm-studio.SwVRf2 0x000000010dcec970 _ZN5realm5Group18validate_top_arrayERKNS_5ArrayERKNS_9SlabAllocE + 1632
2 .io.realm.realm-studio.SwVRf2 0x000000010dcf6a20 _ZN5realm11SharedGroup7do_openERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEbbNS_18SharedGroupOptionsE + 5136
3 .io.realm.realm-studio.SwVRf2 0x000000010d9f9a8c _ZN5realm11SharedGroup4openERNS_11ReplicationENS_18SharedGroupOptionsE + 236
4 .io.realm.realm-studio.SwVRf2 0x000000010d9f9473 _ZN5realm11SharedGroupC2ERNS_11ReplicationENS_18SharedGroupOptionsE + 1587
5 .io.realm.realm-studio.SwVRf2 0x000000010d964951 _ZN5realm5Realm16open_with_configERKNS0_6ConfigERNSt3__110unique_ptrINS_11ReplicationENS4_14default_deleteIS6_EEEERNS5_INS_11SharedGroupENS7_ISB_EEEERNS5_INS_5GroupENS7_ISF_EEEEPS0_ + 1145
6 .io.realm.realm-studio.SwVRf2 0x000000010d964286 _ZN5realm5RealmC2ENS0_6ConfigENSt3__110shared_ptrINS_5_impl16RealmCoordinatorEEE + 278
7 .io.realm.realm-studio.SwVRf2 0x000000010d984a40 _ZZN5realm5Realm17make_shared_realmENS0_6ConfigENSt3__110shared_ptrINS_5_impl16RealmCoordinatorEEEEN19make_shared_enablerC2ES1_S6_ + 84
8 .io.realm.realm-studio.SwVRf2 0x000000010d96ab44 _ZNSt3__110shared_ptrIZN5realm5Realm17make_shared_realmENS2_6ConfigENS0_INS1_5_impl16RealmCoordinatorEEEE19make_shared_enablerE11make_sharedIJS3_S6_EEES8_DpOT_ + 136
9 .io.realm.realm-studio.SwVRf2 0x000000010d97fa3c _ZN5realm5_impl16RealmCoordinator12do_get_realmENS_5Realm6ConfigERNSt3__110shared_ptrIS2_EERNS4_11unique_lockINS4_5mutexEEEb + 260
10 .io.realm.realm-studio.SwVRf2 0x000000010d97f8aa _ZN5realm5_impl16RealmCoordinator9get_realmENS_5Realm6ConfigE + 352
11 .io.realm.realm-studio.SwVRf2 0x000000010d9665fb _ZN5realm5Realm16get_shared_realmENS0_6ConfigE + 113
12 .io.realm.realm-studio.SwVRf2 0x000000010d8cb2cb _ZN5realm2js10RealmClassINS_4node5TypesEE19create_shared_realmEPN2v87IsolateENS_5Realm6ConfigEbONSt3__13mapINSA_12basic_stringIcNSA_11char_traitsIcEENSA_9allocatorIcEEEENSB_ISH_NS0_9ProtectedINS5_5LocalINS5_5ValueEEEEENSA_4lessISH_EENSF_INSA_4pairIKSH_SM_EEEEEESO_NSF_INSP_ISQ_ST_EEEEEEONSB_ISH_NSI_INSJ_INS5_8FunctionEEEEESO_NSF_INSP_ISQ_S10_EEEEEE + 127
13 .io.realm.realm-studio.SwVRf2 0x000000010d8c96c6 _ZN5realm2js10RealmClassINS_4node5TypesEE11constructorEPN2v87IsolateENS5_5LocalINS5_6ObjectEEERNS0_9ArgumentsIS3_EE + 402
14 .io.realm.realm-studio.SwVRf2 0x000000010d8c8a1b _ZN5realm4node10ObjectWrapINS_2js10RealmClassINS0_5TypesEEEE9constructERKN3Nan20FunctionCallbackInfoIN2v85ValueEEE + 333
15 .io.realm.realm-studio.SwVRf2 0x000000010d8c9412 _ZN3Nan3impL23FunctionCallbackWrapperERKN2v820FunctionCallbackInfoINS1_5ValueEEE + 166
16 Electron Framework 0x0000000102c1e4a8 _ZN2v88internallsERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEERKNS0_18BasicBlockProfilerE + 350504
...
What's wrong?
Update
Inspecting manually the realm file I see that the file is written and filled "as expected". Please, note username and asd1#asd.asd that are literal strings from the writing function.

I solved by updating Realm Studio to its beta version.
From:
to:
This because I was trying to open a v4 Realm JS file by using with the latest version of Studio which uses Realm JS v3 internally. So I have had to download and use the beta version of Realm Studio, which uses v4.

Related

Issues observed in " karate-junit5 " library when migrated from version 1.2.0 to 1.3.1

Recently I upgraded the version of karate-junit5 library from 1.2.0 to 1.3.1.
I have a common feature file which contains some common functions used all other scenarios like below sample.
common.feature
#Common
Scenario: Common scenario
* def someFunction =
"""
function(){
karate.log('In some function..');
var textArray = driver.locateAll("//*[#role='button']").map( x => x.text)
karate.log('Button text is: ', textArray);
}
"""
* def getDateInFormat =
"""
function(date){
var curr_date = date.getDate();
if(curr_date < 10)
curr_date = '0' + curr_date;
var curr_month = date.getMonth() + 1;
if(curr_month < 10)
curr_month = '0' + curr_month;
var curr_year = date.getFullYear();
var mod_date = curr_date + '/' + curr_month + '/' + curr_year;
return mod_date;
}
"""
* def sortFunction =
"""
function(sortArr, sortType){
if(sortType == 'asc')
sortArr.sort();
else
sortArr.reverse();
return sortArr;
}
"""
I call above common scenarios from other feature files whenever required. A sample calling feature file would be as below.
Test.feature
Feature: Test feature
Background:
* callonce read('common.feature#Common')
Scenario: Test 1
* print "Today's date is: ", getDateInFormat(new Date())
Scenario: Test 2
* print "Sorted data by A to Z is: ", sortFunction(['Dog', 'Cat', 'Horse'], 'asc')
Scenario: Test 3
* configure driver = { type: 'chrome', addOptions: ['--ignore-certificate-errors', '--incognito', '--disable-gpu', '--window-size=1920,1080', '--no-sandbox'], headless: false }
* configure retry = { count: 10, interval: 2000 }
* driver 'https://www.google.com/'
* someFunction()
All the scenarios 1,2 and 3 are executed properly for 1.2.0 version but throw below errors for when library version is upgraded to 1.3.1 :
For Scenario 1:
" org.graalvm.polyglot.PolyglotException: TypeError: invokeMember (getDate) on java.util.LinkedHashMap#6a969fb8 failed due to: Unknown identifier: getDate "
For Scenario 2:
" org.graalvm.polyglot.PolyglotException: TypeError: invokeMember (sort) on java.util.ArrayList#ff6077 failed due to: Arity error - expected: 1 actual: 0 "
For Scenario 3:
" org.graalvm.polyglot.PolyglotException: ReferenceError: "driver" is not defined "
Can somebody explain what has changed in karate-junit5 library version 1.3.1 from 1.2.0 ?
For Scenario 2, sortArr.reverse() is working properly even in 1.3.1 karate version. Above error is observed for sortArr.sort().
For Scenario 3, if I change the someFunction() to accept driver , like someFunction(driver), then it is executed properly on 1.3.1 version as well.

Invalid array length

I'm trying to test this component on vue, but when I run the test I get the message down bellow:
RangeError: Invalid array length
96 | this.changeLogs.marketConfiguration.productTypes
97 | );
> 98 | return [
| ^
99 | ...new Set(
100 | productTypes.flatMap((productType) => productType.domains || [])
101 | )
I'm using Jest, with vue-test-utils.
And this is the function:
affectedDomains(): string {
const productTypes: ProductTypeConfiguration[] = Object.values(
this.changeLogs.marketConfiguration.productTypes
);
return [
...new Set(
productTypes.flatMap((productType) => productType.domains || [])
)
].join(', ');
}
Found a solution, in my case was to set the "downlevelIteration": true, on tsconfig.json.
Downleveling is TypeScript’s term for transpiling to an older version
of JavaScript. This flag is to enable support for a more accurate
implementation of how modern JavaScript iterates through new concepts
in older JavaScript runtimes.
More info

Using karate-config parameters in a feature file

The karate header examples do not show how to access config values other than baseUrl. When I switch environments (passing in -Dkarate.env=qual as part of the run command) then baseUrl is set correctly.
The problem is, I want to use other config values as shown here but when I run the test, it fails to access config.ApiKey correctly. Instead I get this error
html report:
file:/C:/bitbucket/karate-checkdigit-api/target/surefire-reports/TEST-features.checkdigitapi.VA.html
Tests run: 250, Failures: 0, Errors: 50, Skipped: 175, Time elapsed: 4.112 sec <<< FAILURE!
* def secretKey = config.apiKey(| XYZ | 2110974841 | 204 | Valid |) Time elapsed: 0.005 sec <<< ERROR!
java.lang.RuntimeException: no variable found with name: config
at com.intuit.karate.Script.getValuebyName(Script.java:323)
at com.intuit.karate.Script.evalJsonPathOnVarByName(Script.java:378)
at com.intuit.karate.Script.eval(Script.java:309)
at com.intuit.karate.Script.eval(Script.java:194)
at com.intuit.karate.Script.assign(Script.java:656)
at com.intuit.karate.Script.assign(Script.java:587)
at com.intuit.karate.StepDefs.def(StepDefs.java:265)
at ✽.* def secretKey = config.apiKey(features/checkdigitapi/XYZ.feature:6)
My .feature file and karate-config.js are below.
XYZ.feature
#regression
Feature: Checkdigit Algorithm API
Background:
* url baseUrl
* def secretKey = config.apiKey
* configure ssl = true
Scenario Outline: Testing XYZ algorithm
* configure headers = { KeyId: secretKey, Accept: 'application/json' }
Given path 'headers'
And param url = baseUrl
And params { customerId: '<custcode>', algoId: '<algo>' }
When method get
Then status <val>
Examples:
| algo | custcode | val | comment |
| XYZ | 2110974841 | 204 | Valid |
| XYZ | 7790011614 | 204 | Valid |
| XYZ | 5580015174 | 204 | Valid |
| XYZ | 2110974840 | 400 | expected check digit 1 |
| XYZ | 211097484 | 400 | not 10 digits |
| XYZ | 211097484x | 400 | not numeric |
karate-config.js
function() {
//set up runtime variables based on environment
//get system property 'karate.env'
var env = karate.env;
if (!env) { env = 'dev'; } // default when karate.env not set
// base config
var config = {
env: env,
baseUrl: 'https://localapi.abc123.example.com/api/v1/validate/customerid',
apiKey: ''
}
//switch environment
if (env == 'dev') {
config.baseUrl = 'https://devapi.abc123.example.com/api/v1/validate/customerid';
config.apiKey = 'fake-1ba403ca8938176f3a62de6d30cfb8e';
}
else if (env == 'qual') { //Pre-production environment settings
config.baseUrl = 'https://qualapi.abc123.example.com/api/v1/validate/customerid';
config.apiKey = 'fake-d5de2eb8c0920537f5488f6535c139f2';
}
karate.log('karate.env =', karate.env);
karate.log('config.baseUrl =', config.baseUrl);
karate.log('config.apiKey =', config.apiKey);
return config;
}
(similar issue here, using a separate headers.js: https://github.com/intuit/karate/issues/94)
Keep in mind that all the keys within the JSON object returned by karate-config.js will be injected as variables, and nothing else. So you will not be able to refer to config, but you will certainly be able to refer to apiKey.
I think if you make this simple change, things will start working:
* def secretKey = apiKey
Also, I think you have a problem in the first line of the scenario, it should be:
* configure headers = { KeyId: '#(secretKey)', Accept: 'application/json' }
FYI my final, correctly working XYZ.feature file looks like this now.
The line Given path 'headers' caused header info to creep into the url so it's removed.
XYZ.feature
#regression
Feature: Checkdigit Algorithm API
Background:
* url baseUrl
* def secretKey = apiKey
* configure ssl = true
Scenario Outline: Testing XYZ algorithm
* configure headers = { KeyId: '#(secretKey)', Accept: 'application/json' }
Given url baseUrl
And params { customerId: '<custcode>', algoId: '<algo>' }
When method get
Then status <val>
Examples:
[...]

Yii framework error - "failed to open stream: permission denied"

I have just started to use Yii framework on a windows 7 machine. It's giving me this annoying error and it goes away when I restart the computer.
Can anyone shed some light on what's happening and how to fix it?.. Thanks a bunch
Here is the error I get:
PHP warning
copy(C:\www\corp\assets\96296f5a\js\ckeditor\plugins\imagepaste2.3.zip): failed to open stream: Permission denied
C:\www\yii-1.1.13\framework\utils\CFileHelper.php(131)
119
120 $folder=opendir($src);
121 while(($file=readdir($folder))!==false)
122 {
123 if($file==='.' || $file==='..')
124 continue;
125 $path=$src.DIRECTORY_SEPARATOR.$file;
126 $isFile=is_file($path);
127 if(self::validatePath($base,$file,$isFile,$fileTypes,$exclude))
128 {
129 if($isFile)
130 {
131 copy($path,$dst.DIRECTORY_SEPARATOR.$file);
132 if(isset($options['newFileMode']))
133 chmod($dst.DIRECTORY_SEPARATOR.$file,$options['newFileMode']);
134 }
135 elseif($level)
136 self::copyDirectoryRecursive($path,$dst.DIRECTORY_SEPARATOR.$file,$base.'/'.$file,$fileTypes,$exclude,$level-1,$options);
137 }
138 }
139 closedir($folder);
140 }
141
142 /**
143 * Returns the files found under the specified directory and subdirectories.
Stack Trace
#0
+
C:\www\yii-1.1.13\framework\utils\CFileHelper.php(131): copy("C:\www\corp\protected\extensions\bootstrap\assets\js\ckeditor\pl...", "C:\www\corp\assets\96296f5a\js\ckeditor\plugins\imagepaste2.3.zi...")
#1
+
C:\www\yii-1.1.13\framework\utils\CFileHelper.php(136): CFileHelper::copyDirectoryRecursive("C:\www\corp\protected\extensions\bootstrap\assets\js\ckeditor\pl...", "C:\www\corp\assets\96296f5a\js\ckeditor\plugins", "/js/ckeditor/plugins", array(), ...)
#2
+
C:\www\yii-1.1.13\framework\utils\CFileHelper.php(136): CFileHelper::copyDirectoryRecursive("C:\www\corp\protected\extensions\bootstrap\assets\js\ckeditor", "C:\www\corp\assets\96296f5a\js\ckeditor", "/js/ckeditor", array(), ...)
#3
+
C:\www\yii-1.1.13\framework\utils\CFileHelper.php(136): CFileHelper::copyDirectoryRecursive("C:\www\corp\protected\extensions\bootstrap\assets\js", "C:\www\corp\assets\96296f5a\js", "/js", array(), ...)
#4
+
C:\www\yii-1.1.13\framework\utils\CFileHelper.php(63): CFileHelper::copyDirectoryRecursive("C:\www\corp\protected\extensions\bootstrap\assets", "C:\www\corp\assets\96296f5a", "", array(), ...)
#5
+
C:\www\yii-1.1.13\framework\web\CAssetManager.php(251): CFileHelper::copyDirectory("C:\www\corp\protected\extensions\bootstrap\assets", "C:\www\corp\assets\96296f5a", array("exclude" => array(".svn", ".gitignore"), "level" => -1, "newDirMode" => 511, "newFileMode" => 438))
#6
–
C:\www\corp\protected\extensions\bootstrap\components\Bootstrap.php(458): CAssetManager->publish("C:\www\corp\protected\extensions\bootstrap\assets", false, -1, true)
453 if (isset($this->_assetsUrl))
454 return $this->_assetsUrl;
455 else
456 {
457 $assetsPath = Yii::getPathOfAlias('bootstrap.assets');
458 $assetsUrl = Yii::app()->assetManager->publish($assetsPath, false, -1, YII_DEBUG);
459 return $this->_assetsUrl = $assetsUrl;
460 }
461 }
462
463 /**
#7
–
C:\www\corp\protected\extensions\bootstrap\components\Bootstrap.php(163): Bootstrap->getAssetsUrl()
158 * #param string $cssFile the css file name to register
159 * #param string $media the media that the CSS file should be applied to. If empty, it means all media types.
160 */
161 public function registerAssetCss($cssFile, $media = '')
162 {
163 Yii::app()->getClientScript()->registerCssFile($this->getAssetsUrl() . "/css/{$cssFile}", $media);
164 }
165
166 /**
167 * Registers the core JavaScript.
168 * #since 0.9.8
#8
–
C:\www\corp\protected\extensions\bootstrap\components\Bootstrap.php(124): Bootstrap->registerAssetCss("bootstrap.css")
119 /**
120 * Registers the Bootstrap CSS.
121 */
122 public function registerCoreCss()
123 {
124 $this->registerAssetCss('bootstrap' . (!YII_DEBUG ? '.min' : '') . '.css');
125 }
126
127 /**
128 * Registers the Bootstrap responsive CSS.
129 * #since 0.9.8
#9
+
C:\www\corp\protected\extensions\bootstrap\components\Bootstrap.php(102): Bootstrap->registerCoreCss()
#10
+
C:\www\yii-1.1.13\framework\base\CModule.php(387): Bootstrap->init()
#11
+
C:\www\yii-1.1.13\framework\base\CModule.php(523): CModule->getComponent("bootstrap")
#12
+
C:\www\yii-1.1.13\framework\base\CApplication.php(152): CModule->preloadComponents()
#13
+
C:\www\yii-1.1.13\framework\YiiBase.php(125): CApplication->__construct("C:\www\corp/protected/config/main.php")
#14
+
C:\www\yii-1.1.13\framework\YiiBase.php(98): YiiBase::createApplication("CWebApplication", "C:\www\corp/protected/config/main.php")
#15
+
C:\www\corp\index.php(13): YiiBase::createWebApplication("C:\www\corp/protected/config/main.php")
2013-02-25 11:29:18 Apache/2.2.22 (Win32) PHP/5.3.13 Yii Framework/1.1.13
The error basically says that YII is not able to copy the required assets from the extensions on to the assets directory at runtime.
The directory C:\www\corp where your YII project exists should be writable by the web server process.
I would see if there is there a firewall/anti-virus that might be blocking the web server from creating files. Try reading the web server log.

Titanium Mobile - PhotoGallery - Success callback - event property - media.file returns null

Titanium SDK: 2.1.1, Host OS: Mac OS X 10.6.8, Mobile platform: iOS 5
I am un-able to access some properties of 'Blob' object returned by Titanium.Media.openPhotoGallery's success callback. The properties un-accessible are 'file' and 'nativePath', however I can access properties like 'height', 'width' and 'mimeType'. I'm testing on simulator.
Here is what I coded so far.
Titanium.Media.openPhotoGallery({
success : function(event) {
var image = event.media;
if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
// following properties are accessible
Ti.API.info(' event.media = ' + event.media );
Ti.API.info('event.media.height = ' + event.media.height );
Ti.API.info('event.media.width = ' + event.media.width );
Ti.API.info('event.mediaType = ' + event.mediaType );
// following properties are un-accessible
Ti.API.info(' event.media.nativePath = ' + event.media.nativePath );
Ti.API.info(' event.media.file = ' + event.media.getFile() );
},
cancel : function() {},
error : function(error) {},
allowEditing : true,
mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO]
});
You cannot access file or file native path from iphone photo gallery. its not accessible. although you can store the selected image on file system or sqlite db and then perform all your tasks on it ...:)