2
votes

I am working on a demo app for my client. The objective of this demo app is to show that Worklight Hybrid app can work on all the environments. My demo app is working fine in Android Emulator but when I am transfering the zip file present in Package folder in Iphone environment folder to a MAC system having XCODE 5.0 and trying to run the app, I am getting this error-

"error JSON.stringify()ing argument: TypeError: JSON.stringify cannot serialize cyclic structures"

I am using Worklight V6 and default dojo version provided in it. I searched on net and found few more people are also struggling with this. One example is reported here-

http://dojo-toolkit.33424.n3.nabble.com/ERROR-error-JSON-stringify-ing-argument-TypeError-JSON-stringify-cannot-serialize-cyclic-structures-td3996156.html

can someone please tell me what is the root cause of this error? It seems problem is either with the simulator or the cordova plugin version used in worklight. Is there any workaround for this?

Here is my XCode Log-

   2013-11-17 22:08:02.290 KaiserTestApp[6396:a0b] ***TeaLeaf Library Version***:      8.8.1.56 
   2013-11-17 22:08:03.002 KaiserTestApp[6396:a0b] Application windows are expected to  have a root view controller at the end of application launch 
   2013-11-17 22:08:04.129 KaiserTestApp[6396:3e07] Web resources integrity test is disabled. 
   2013-11-17 22:08:04.134 KaiserTestApp[6396:a0b] Multi-tasking -> Device: YES, App: YES 
   2013-11-17 22:08:05.003 KaiserTestApp[6396:a0b] Resetting plugins due to page load. 
   2013-11-17 22:08:05.509 KaiserTestApp[6396:a0b] Finished load of: file:///Users/prasuna/Library/Application Support/iPhone Simulator/7.0.3/Applications/5BFF2FA8-9E4B-45D3-B991-43EE8008A5F4/Library/Application Support/www956725435/default/KaiserTestApp.html 
   2013-11-17 22:08:05.524 KaiserTestApp[6396:a0b] DEPRECATION NOTICE: The Connection ReachableViaWWAN return value of '2g' is deprecated as of Cordova version 2.6.0 and will be changed to 'cellular' in a future release.  
   2013-11-17 22:08:05.532 KaiserTestApp[6396:a0b] {     appVersionPref = "1.0";     freeSpace = 132894613504;     wlSkinLoaderChecksum = "(null)";     wlSkinName = default; } 
   2013-11-17 22:08:05.541 KaiserTestApp[6396:a0b] [DEBUG] wlclient init started 
   2013-11-17 22:08:05.542 KaiserTestApp[6396:a0b] [DEBUG] Read cookies: null 
   2013-11-17 22:08:05.542 KaiserTestApp[6396:a0b] [DEBUG] CookieMgr read cookies: {} 
   2013-11-17 22:08:05.547 KaiserTestApp[6396:a0b] [DEBUG] before: app init onSuccess 
   2013-11-17 22:08:05.548 KaiserTestApp[6396:a0b] [DEBUG] after: app init onSuccess 
   2013-11-17 22:08:05.548 KaiserTestApp[6396:a0b] [DEBUG] added onPause event handler  
   2013-11-17 22:08:05.549 KaiserTestApp[6396:a0b] [DEBUG] wlclient init success 
   2013-11-17 22:08:05.638 KaiserTestApp[6396:a0b] [LOG] I am in main js file 
   2013-11-17 22:08:05.638 KaiserTestApp[6396:a0b] [DEBUG] HomeController created 
   2013-11-17 22:08:05.639 KaiserTestApp[6396:a0b] [DEBUG] Testing log 
   2013-11-17 22:09:21.000 KaiserTestApp[6396:a0b] [ERROR] error JSON.stringify()ing argument: TypeError: JSON.stringify cannot serialize cyclic structures. 
   2013-11-17 22:09:21.000 KaiserTestApp[6396:a0b] [ERROR] error JSON.stringify()ing argument: TypeError: JSON.stringify cannot serialize cyclic structures.  

I also tried running the demo app in IOS 6 but I am getting below error at the time of compilation. Can someone please help me to understand what this means and how can I solve this?

setenv WRAPPER_EXTENSION app

setenv WRAPPER_NAME KaiserTestApp.app

setenv WRAPPER_SUFFIX .app

setenv XCODE_APP_SUPPORT_DIR /Applications/Xcode.app/Contents/Developer/Library/Xcode

setenv XCODE_PRODUCT_BUILD_VERSION 4H1503

setenv XCODE_VERSION_ACTUAL 0463

setenv XCODE_VERSION_MAJOR 0400

setenv XCODE_VERSION_MINOR 0460

setenv YACC yacc

/bin/sh -c /Users/wppa/Library/Developer/Xcode/DerivedData/KaiserTestProjKaiserTestAppIphone-egvnwnfozzvukmdsxsnkzlsfjwgz/Build/Intermediates/KaiserTestProjKaiserTestAppIphone.build/Debug-iphonesimulator/KaiserTestProjKaiserTestAppIphone.build/Script-427B829D1393724500F223DC.sh


   Running a custom build phase script: buildtime.sh

   /Users/wppa/Library/Developer/Xcode/DerivedData/KaiserTestProjKaiserTestAppIphone-      egvnwnfozzvukmdsxsnkzlsfjwgz/Build/Intermediates/KaiserTestProjKaiserTestAppIphone.build/Debug-iphonesimulator/KaiserTestProjKaiserTestAppIphone.build/Script-427B829D1393724500F223DC.sh: line 7: /Users/wppa/Kaiser/buildtime.sh: Permission denied

   DONE with script: buildtime.sh (exitStatus=126)\n\n
1
That error means that an object was passed to JSON.stringify which has references to itself within its sub-objects (hence "cyclic structures"). I'm pretty sure that JSON.stringify can't handle such structures on any platform (it would cause an infinite recursion), so it is unclear to me why this would only occur on iOS. If you can post a stack trace and part of the JSON object causing the problem that might help isolate the issue... - Ken Franqueiro
Hi Ken,As I have mentioned in the question My App is working fine in Android emulator and the problem is only with IOS simulator. I did a bit troubleshooting and found that problem could be that simulator is not compatible with dojo. At first code was throwing error at dojo Ready function. When I removed it, it started throwing error at some other line which is again a dojo code. Dojo is internally using Json.strigify and somehow IOS Simulator has problem with that. - Anil kumar
I would much sooner think the issue is in Worklight or custom code - I have not seen this issue using Dojo on iOS... that's why I asked for a stack trace. Yes Dojo uses JSON.stringify in certain cases, but it's what's being passed to that (and what's doing the passing) that's the problem. - Ken Franqueiro
By Stack trace,do you mean the log that I am getting in the Xcode?? I have updated my question with the log. I am getting JSON.stringify error when the dojo Ready function is trying to execute. - Anil kumar
@Idan- I am waiting for your special comment on this. Please help. - Anil kumar

1 Answers

0
votes

Regarding the specific issue you're having in iOS 6, it is in fact not related to iOS 6 and also is not at all related to this question ("... cannot serialize cyclic structures..."). I suggest splitting it to another question or just removing it.

Running a custom build phase script: buildtime.sh

/Users/wppa/Library/Developer/Xcode/DerivedData/KaiserTestProjKaiserTestAppIphone- egvnwnfozzvukmdsxsnkzlsfjwgz/Build/Intermediates/KaiserTestProjKaiserTestAppIphone.build/Debug-iphonesimulator/KaiserTestProjKaiserTestAppIphone.build/Script-427B829D1393724500F223DC.sh: line 7: /Users/wppa/Kaiser/buildtime.sh: Permission denied

You're missing execute permissions for the file buildtime.sh.

The problem and solution are explained in detail in my answer to this question: IBM Worklight - "Permission denied" when building in Xcode

I suggest following these steps:

Change the permission using CHMOD:

  1. Copy the path to the folder holding the buildtime.sh file
  2. Open the Terminal app
  3. Run the following command (but use your own path from 1 above): chmod 755 /Users/idan/Documents/Worklight/workspace-6001/TestProject/apps/TestApp/iphone/native/buildtime.sh