Skip to content

JSON text did not start with array or object and option to allow fragments not set. #166

Closed

Description

@jaydeep82

Hello Friends,

I've migrated the parse-server code on my aws ec2 server. Before testing to my code, I've tried to connect to parse server as mentioned below.

Parse.initializeWithConfiguration(ParseClientConfiguration(block: { ( configuration : ParseMutableClientConfiguration ) -> Void in
configuration.applicationId = PARSE_DEVELOPMENT_APPLICATION_ID
configuration.clientKey = PARSE_DEVELOPMENT_CLIENT_KEY
configuration.server = "https://api.parse.com"
}))

I have used Parse (1.12.0) SDK in this App.

When I start my iOS App, I'm getting following error message.

2016-02-02 12:42:59.684 MyParseApp[5101:61497] [Error]: Failed to run command eventually with error: Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

Could you assist me here what is wrong ? Any suggestion/assistance would be highly appreciated.

Thank you.

Activity

  1. gfosco commented on Feb 2, 2016

    @gfosco
    Contributor

    This is pointing at api.parse.com instead of a parse-server instance, but I'm curious if @nlutsenko sees anything else strange here.

  2. jaydeep82 commented on Feb 2, 2016

    @jaydeep82
    Author

    Thank you Fosco for quick reply.

    I've migrated the code to my aws ec2 server and database on mongolab.

    Using curl, I'm able to call the cloud function, insert data in mongodb, get data from mongodb.

    But in iOS(Swift) App, I'm getting following error message :

    2016-02-02 11:39:59.718 MyApp[4168:43783] [Error]: schema mismatch for _Session.createdWith; expected map but got object (Code: 111, Version: 1.12.0)
    error in register : schema mismatch for _Session.createdWith; expected map but got object

    is it different issue ?

  3. nlutsenko commented on Feb 2, 2016

    @nlutsenko
    Contributor

    Few things:

    • Error 3840 means that we couldn't parse out the JSON response back from the server. I would recommend adding logging on the server end of things and looking into request/response trace for this call.
    • The second one is actually a client-propagation of the server error. Looks like you have a different schema already set for the createdWith property on the _Session. Looks like at some point it received a map, instead of a Parse Object and now it fails to validate since the schema is already set. I would recommend taking a look at the _Session collection object schema and making the adjustment either on the server or on the client.
  4. nlutsenko commented on Feb 2, 2016

    @nlutsenko
    Contributor

    Hope this helps, let us know if there is anything we missed or anything that is not quite clear.

  5. jaydeep82 commented on Feb 2, 2016

    @jaydeep82
    Author

    Hi Nikita, thank you very much for your quick reply.

    Regarding second issue, this class/collection _Session is part of my Parse Application and generated by Parse. Actually I've migrated this data from Parse to Mongodb hosted on MongoLab.

    "createdWith" : {
            "action" : "login",
            "authProvider" : "password"
        }
    
    

    I've not done any manual changes in _Session schema. Is this schema mismatch issue because of database migration from parse to mongodb ?

  6. latne1ec commented on Feb 2, 2016

    @latne1ec

    Adding /parse to the end of my configuration.server url worked for me.

  7. jaydeep82 commented on Feb 3, 2016

    @jaydeep82
    Author

    Hi @latne1ec , Thank you for your reply.

    Could you share more details about which platform you have used for parse deployment ?
    I've used heroku and mongolab.

    I've also added /parse to the end of my configuration.server url.

  8. latne1ec commented on Feb 3, 2016

    @latne1ec

    I set up an ec2 instance on aws to host my mongodb database and heroku for the parse-server api.

  9. flovilmart commented on Feb 6, 2016

    @flovilmart
    Contributor

    @gfosco isn't the API URL for parse https://api.parse.com/1/

  10. KathleenFMalone commented on Mar 9, 2016

    @KathleenFMalone

    I had the same problem and added parse at the end of the server URL and it worked. Thank you latne1ec!!!!

  11. michael-mckenna commented on Mar 19, 2016

    @michael-mckenna

    /parse at the end of the url worked for me too.

  12. rendragon83 commented on Mar 22, 2016

    @rendragon83

    I added /parse and it is not working for me. I have the same issues as @jaydeep82, I am also using Heroku with mongolab. I have tried two different ways to do this in swift, but I still get the same error. These are the two ways I have done it:

    let configuration = ParseClientConfiguration(block: {
    (ParseMutableClientConfiguration) -> Void in

            ParseMutableClientConfiguration.applicationId = "appID"
            ParseMutableClientConfiguration.clientKey = "appMasterKey"
            ParseMutableClientConfiguration.server = "https://MyAppName.herokuapp.com/parse"
        })
    
        Parse.initializeWithConfiguration(configuration);
    

    and I also tried:

    let configuration = ParseClientConfiguration {
    $0.applicationId = "appID"
    $0.clientKey = "appMasterKey"
    $0.server = "https://MyAppName.herokuapp.com/parse"
    }

        Parse.initializeWithConfiguration(configuration)
    

    Both ways I still get error code of 3840 "JSON text did not start with array or object and option to allow fragments not set."

    2016-03-24 11:20:31.538 ClockIn[4668:676920] Warning: A long-running operation is being executed on the main thread.
    Break on warnBlockingOperationOnMainThread() to debug.
    Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

    Either of these work if I use https://api.parse.com/1/ for the server, but does not work if I try to use my own server. Does anyone know why this is happening, or is it just broken when using iOS and swift?

  13. bchapin commented on Apr 20, 2016

    @bchapin

    I just tried migrating my app to Heroku. Some things work, others do not. I am getting the error "JSON text did not start with array or object and option to allow fragments not set" when saving objects.

    My app is configured using:

    [Parse initializeWithConfiguration:[ParseClientConfiguration configurationWithBlock:^(id configuration) {
    configuration.applicationId = @"xxxxx";
    //configuration.clientKey = @"";
    configuration.server = @"http://myappname.heroku.com/parse";
    }]];

    It all works fine when pointing to the parse servers

    Any help? Suggestions?

  14. 6 remaining items

  15. candork commented on May 2, 2016

    @candork

    Getting the same problem. I have parse installed on AWS Elastic Bean Stalk with database on mLab.

    This happens very randomly.

    2016-05-02 09:43:43.631 app[1387:388806] [Error]: Failed to run command eventually with error: Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

    2016-05-02 09:43:43.694 app[1387:388806] [Error]: Failed to run command eventually with error: Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

    2016-05-02 09:43:43.755 app[1387:388806] [Error]: Failed to run command eventually with error: Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

  16. candork commented on May 2, 2016

    @candork

    Here are the error logs from the server

    /var/log/nginx/error.log

    2016/05/02 13:42:15 [error] 3188#0: *142495 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: , server: , request: "POST /parse/classes/Comment HTTP/1.1", upstream: "http://127.0.0.1:8081/parse/classes/Comment", host: "api.snapchat.com"

    2016/05/02 13:42:15 [error] 3188#0: *142486 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: , server: , request: "POST /parse/classes/SoundData/l8Kkl0B3NK HTTP/1.1", upstream: "http://127.0.0.1:8081/parse/classes/SoundData/l8Kkl0B3NK", host: "hidden-prefix.us-east-1.elasticbeanstalk.com"

    2016/05/02 13:42:18 [error] 3188#0: *142486 connect() failed (111: Connection refused) while connecting to upstream, client: , server: , request: "POST /parse/classes/Comment HTTP/1.1", upstream: "http://127.0.0.1:8081/parse/classes/Comment", host: "api.snapchat.com"

    2016/05/02 13:42:19 [error] 3188#0: *142517 connect() failed (111: Connection refused) while connecting to upstream, client: , server: , request: "POST /parse/functions/FeedCloudFunction_getFeedOfUser HTTP/1.1", upstream: "http://127.0.0.1:8081/parse/functions/FeedCloudFunction_getFeedOfUser", host: "api.snapchat.com"

    2016/05/02 13:42:33 [error] 3188#0: *142508 upstream prematurely closed connection while reading response header from upstream, client: 10.180.203.86, server: , request: "POST /parse/classes/SoundData/3NbbVRJIIo HTTP/1.1", upstream: "http://127.0.0.1:8081/parse/classes/SoundData/3NbbVRJIIo", host: "hidden-prefix.us-east-1.elasticbeanstalk.com"

    2016/05/02 13:42:33 [error] 3188#0: *142508 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 10.180.203.86, server: , request: "POST /parse/classes/SoundData/3NbbVRJIIo HTTP/1.1", upstream: "http://127.0.0.1:8081/parse/classes/SoundData/3NbbVRJIIo", host: "hidden-prefix.us-east-1.elasticbeanstalk.com"

    2016/05/02 13:42:33 [error] 3188#0: *142508 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 10.180.203.86, server: , request: "POST /parse/classes/SoundData/3NbbVRJIIo HTTP/1.1", upstream: "http://127.0.0.1:8081/parse/classes/SoundData/3NbbVRJIIo", host: "hidden-prefix.us-east-1.elasticbeanstalk.com"

    2016/05/02 13:43:01 [error] 3188#0: *142550 upstream prematurely closed connection while reading response header from upstream, client: , server: , request: "GET /parse/classes/_User/ihSR4oZH5i HTTP/1.1", upstream: "http://127.0.0.1:8081/parse/classes/_User/ihSR4oZH5i", host: "api.snapchat.com"

    2016/05/02 13:43:01 [error] 3188#0: *142552 upstream prematurely closed connection while reading response header from upstream, client: , server: , request: "POST /parse/classes/_User/p8WZn7NLL6 HTTP/1.1", upstream: "http://127.0.0.1:8081/parse/classes/_User/p8WZn7NLL6", host: "hidden-prefix.us-east-1.elasticbeanstalk.com"

    2016/05/02 13:43:01 [error] 3188#0: *142562 upstream prematurely closed connection while reading response header from upstream, client: 10.180.203.86, server: , request: "POST /parse/config HTTP/1.1", upstream: "http://127.0.0.1:8081/parse/config", host: "hidden-prefix.us-east-1.elasticbeanstalk.com"

  17. jrespuny commented on May 23, 2016

    @jrespuny

    I am getting the same error after moving the mandrill initializer to the top of the cloud code:
    Error loggin in: Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

    // Use Parse.Cloud.define to define as many cloud functions as you want.
    // For example:
    
    var Mandrill = require('mandrill-api/mandrill');
    Mandrill.initialize('XXXXXXXXXXXXXXXXXXXXX');
    
    Parse.Cloud.define("hello", function(request, response) {
      response.success("Hello world!");
    });
    
    
    Parse.Cloud.define("sendMail", function(request, response) {
    // Moved this line to the top
    //   var Mandrill = require('mandrill-api/mandrill');
    //   Mandrill.initialize('XXXXXXXXXXXXXXXXXXXXX');
        Mandrill.sendEmail({
            message: {
                text: request.params.text,
                subject: request.params.subject,
                from_email: request.params.fromEmail,
                from_name: request.params.fromName,
                to: [
                    {
                        email: request.params.toEmail,
                        name: request.params.toName
                    }
                ]
            },
            async: true
            },{
            success: function(httpResponse) {
                console.log(httpResponse);
                response.success("Email sent");
            },
            error: function(httpResponse) {
                console.error(httpResponse);
                response.error("Email not sent");
            }
        });
    });
    
    

    Before that I was getting:

    [Error]: {"code":1,"message":"Internal server error."} (Code: 1, Version: 1.13.0)

    when calling the sendMail function

  18. kumareshsaran commented on Mar 30, 2017

    @kumareshsaran

    I am Also got the same issues in JSON parisng.i am new to swift code so i don't know how to fix this issues. please help me to fix this issues

    "Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}"

  19. wellkeptbeauty commented on Apr 27, 2017

    @wellkeptbeauty

    when i call cloud function from Xcode, getting following result
    Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

  20. flovilmart commented on May 6, 2017

    @flovilmart
    Contributor

    @wellkeptbeauty can you open a new issue with all required details?

  21. giusecapo commented on Jun 14, 2017

    @giusecapo

    @wellkeptbeauty same here, how did you fix?

  22. AnAppDev01 commented on Nov 3, 2017

    @AnAppDev01

    I've been stuck for 3 weeks with this problem. It happens when I call saveInBackgroundWithBlock in parse ios sdk. I get the same connection refused in my logs as candork does. I am desperate to fix this. Our app is completely blocked. It's completely random and I cannot reproduce it using any steps. Sometimes it fails, sometimes it doesn't. It appears to only happen in ios11. There is no change in ios code and it has been working fine for 2 years, then all of a sudden....

  23. montymxb commented on Nov 3, 2017

    @montymxb
    Contributor

    @ArchonLight If you can provide details/logs of the specific request causing the error, and any relevants logs server side, that would be most helpful.

  24. flovilmart commented on Nov 3, 2017

    @flovilmart
    Contributor

    This is likely to be caused by a 5xx error on the server, or an uncaught exception that would make the error not being properly set in the response. OR a response from a proxy, that terminated the connection without responding with a JSON response.

  25. AnAppDev01 commented on Nov 3, 2017

    @AnAppDev01

    My object to save in mongoDB:
    Printing description of photo:

    <Photo: 0x1c08d4a50, objectId: new, localId: (null)> {
        city = Powell;
        imageUrl = "http://res.cloudinary.com/xxxxxxxx/image/upload/v1509739983/dnx04b374qe0khgru1rh.jpg";
        likes = 0;
        trip = "<Trip: 0x1c0eaba00, objectId: jAcW7QEIsu, localId: (null)>";
        tripName = "Test again";
        user = "<PFUser: 0x1c02e3e80, objectId: mzITFRYJjy, localId: (null)>";
        userName = xxxxxxxxx;
        usersWhoHaveLiked =     (
        );
    }
    

    my ios code:

     [photo saveInBackgroundWithBlock:^(BOOL succeeded, NSError * _Nullable error) {
                      if(error) {
                          NSLog(@"Parse save failure...");
                          completionBlock(nil, error, photo);
                      }else {
                          NSLog(@"Parse save success...");
                          completionBlock(YES, nil, photo);
                      }
                  }];
    

    Console Error:

    [Error]: Failed to run command eventually with error: Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

    AWS EB log errors:

    2017/10/20 03:43:01 [warn] 3513#0: duplicate MIME type "text/html" in /etc/nginx/sites-enabled/elasticbeanstalk-nginx-docker-proxy.conf:11
    2017/10/20 20:52:55 [error] 16663#0: *60670 upstream prematurely closed connection while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: , request: "POST /parse/classes/Activity HTTP/1.1", upstream: "http://xxx.xxx.xxx.xxx:8080/parse/classes/Activity", host: "api.xxxxxxxxxxxx.com"
    2017/10/20 20:52:55 [error] 16663#0: *60670 connect() failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: , request: "POST /parse/classes/Activity HTTP/1.1", upstream: "http://xxx.xxx.xxx.xxx:8080/parse/classes/Activity", host: "api.xxxxxxxxxxx.com"
    2017/10/20 20:52:55 [error] 16663#0: *60712 connect() failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: , request: "POST /parse/classes/Photo HTTP/1.1", upstream: "http://xxx.xxx.xxx.xxx:8080/parse/classes/Photo", host: "api.xxxxxxxx.com"

    ^ and a bunch more just like it

  26. flovilmart commented on Nov 3, 2017

    @flovilmart
    Contributor

    what about your parse-server logs? did the process crash?

    Because: 60670 connect() failed (111: Connection refused) while connecting to upstream

  27. montymxb commented on Nov 3, 2017

    @montymxb
    Contributor

    Is it always marked first by upstream prematurely closed connection while reading response header from upstream, with the following connections refused? That does seem a lot like a crash :/. It would definitely help to see the corresponding parse-server logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:questionSupport or code-level question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions