Weird error in cloud functions

Hey guys, I got 2 questions, but first:

The error shown in console and logs:

{
  "code": 121,
  "level": "error",
  "message": "Nested keys should not contain the '$' or '.' characters",
  "stack": "Error: Nested keys should not contain the '$' or '.' characters\n    at C:\\Users\\User1\\Documents\\GitHub\\testing-parse-server\\node_modules\\parse-server\\lib\\Controllers\\DatabaseController.js:522:21\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)",
  "timestamp": "2022-09-13T18:00:00.162Z"
}

The code used:

/* Some context:
*
* ipsArray = { '::ffff:127.0.0.1': { loginCounter: 0, logoutCounter: 1 } }
* So I can't use the key "::ffff:127.0.0.1" because it contains the "." char
*/

userRow.set("ip", ipsArray);
try {
  await userRow.save(null, { useMasterKey: true });
} catch(error) {
  throw "Something went wrong on logout. (Code 0)";
}

So the problem is that I can’t have an object key with the “$” or “.” character.
I suppose I can replace every “.” and “$” for another char.

  1. But why can’t we use this chars in object keys? I can set it manually in my database so it’s not a problem with MongoDB. Is this a limitation of Parse?

  2. Now the weird one, using “throw” inside that catch crashes the server, why? I usually use “throw” without any problems and it just returns the message to the client without crashing the server.

Thanks In Advance!

  1. It is a Parse limitation.
  2. Still not sure why the crash.

You may check the issue. Server crashed if asynchronous function get error. (uncaughtException) · Issue #8193 · parse-community/parse-server · GitHub

1 Like

Just a note, If you use throw new Error(error.message) instead of throwing a string it doesn’t crash.

I recommend to use new Parse.Error.