parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Getting parse-server error on Cloud Code method that utilizes increment in object field (to advance count)

Open sprabs opened this issue 10 years ago • 5 comments

When the iOS client calls a cloud code method that uses "increment" on a field, we see an internal server error in the logs. To clarify, this is not on the Installation class for badge. This is in general for another object type.

### Steps to reproduce

The iOS client calls a cloud code method that looks something like this (in an internal module):

  var promise = new Parse.Promise();
  var entityQuery = new Parse.Query("Topics");
  entityQuery.equalTo("objectId", entityId);
  entityQuery.first({

    success: function(entity) {

      entity.increment("currentViews", incrementValue);
      entity.save(null, {

        success: function(entity) {
          promise.resolve();
        },

        error: function(error) {
          promise.reject("incrementViewCount failed with error: " + error.message + " while saving " + entityType + " with objectId: " + entityId);
        }

      });

    },

    error: function(error) {
      promise.reject("incrementViewCount method failed with error: " + error.message);
    }

  });

  return promise;

};

Expected Results

The field should increment or decrement by the value specified.

Actual Outcome

We see an internal server error.

Environment Setup

  • Server
    • parse-server version: 2.2.15 (latest available at the time of this post)
    • Operating System: 64bit Amazon Linux 2016.03 v2.1.1 running Node.js (v4.4.3)
    • Hardware: t2.medium
    • Localhost or remote server? AWS Elastic Beanstalk
  • Database
    • MongoDB version: mLab dedicated cluster (v3.0.10)

Logs/Trace

On the iOS client, I see this error on XCode: [Error]: {"code":1,"message":"Internal server error."} (Code: 1, Version: 1.13.0)

When I comment out that method (preventing it from getting called), the error disappears.

sprabs avatar Jul 07 '16 23:07 sprabs

Specifically, it seems to error when I try incrementing by a negative number. I have had no problem with this on Cloud Code hosted through parse.com.

@hramos Any idea how to workaround this?

sprabs avatar Jul 08 '16 00:07 sprabs

Also, the same thing works fine through REST API (without error):

curl -X PUT \

-H "X-Parse-Application-Id: [APP_ID]"
-H "X-Parse-REST-API-Key: [REST_ID]"
-H "Content-Type: application/json"
-d '{"currentViews":{"__op":"Increment","amount":-1}}'
https://[EB endpoint]/classes/Topics/[oid]

sprabs avatar Jul 08 '16 00:07 sprabs

Can you try running with VERBOSE=1 so we see what request is going on in CloudCode and why it fails?

flovilmart avatar Jul 08 '16 00:07 flovilmart

Hi @flovilmart. Turns out I had a very silly issue.

In case anyone else hits it... looks like pathnames are handled a little differently between parse.com and parse-server. When you require a module, say "topics.js" in parse.com, you can get away with "topics." The parse-server is less forgiving since I've constructed the cloud code there to use absolute paths.

The fix was to change "topics" to "topics.js"

sprabs avatar Jul 08 '16 01:07 sprabs

that's odd that you need the .js extension. but glad you found the problem!

flovilmart avatar Jul 08 '16 01:07 flovilmart