Moralis cloud Error

Can anyone please explain this error to me, not sure what it means, but I have two aftersave cloud functions on my cloud script, one works but the other doesn’t

Error: Invalid function: “pluginsReady”
at handleCloudFunction (/moralis-server/lib/Routers/FunctionsRouter.js:201:13)
at /moralis-server/lib/PromiseRouter.js:85:20
at processTicksAndRejections (node:internal/process/task_queues:96:5)

You get this when the server is loading. This error is probably not related to the cloud function.

Do you see any other errors related to the cloud function?

You can try using the logger to check if the function is working.

I have a couple of functions on my cloud functions, but I can only see the out put of one logger from the very first function

``Moralis.Cloud.afterSave(“SongListed”, async (request) => {
const confirmed = request.object.get(“confirmed”);
const logger = Moralis.Cloud.getLogger();
logger.info(“looking for the confirmed tx…”);

//checking if thre item has beeen confirmed/listed
if (confirmed) {
logger.info(“Found item…”);
//checking if ActiveItem existed and if not, create it
const ActiveItem = Moralis.Object.extend(“ActiveItem”);

const query = Moralis.Cloud.Query("ActiveItem");
query.equalTo("marketplaceAddress", request.object.get("address"));
query.equalTo("nftAddress", request.object.get("nftAddress"));
query.equalTo("tokenId", request.object.get("tokenId"));
query.equalTo("seller", request.object.get("seller"));

const alreadyListed = await query.first();
if (alreadyListed) {
  logger.info(`Deleting already listed ${request.object.get("objectID")}`);
  await alreadyListed.destroy();
  logger.info(
    `Deleted item already Listed with token id ${request.object.get(
      "tokenId"
    )} at address${request.object.get("address")} since its already listed`
  );
}

const activeItem = new ActiveItem();
activeItem.set("marketplaceAddress", request.object.get("address"));
activeItem.set("nftAddress", request.object.get("nftAddress"));
activeItem.set("price", request.object.get("price"));
activeItem.set("tokenId", request.object.get("tokenId"));
activeItem.set("seller", request.object.get("seller"));

logger.info(
  `Adding Address ${request.object.get(
    "address"
  )}. TokenID:${request.object.get("tokenId")}}`
);

logger.info("saving...");
await activeItem.save();

}
});

Moralis.Cloud.afterSave(“ItemCanceled”, async (request) => {
//getting the confirm status from the moralis serveer
const confirmed = request.object.get(“confirmed”);
const logger = Moralis.Cloud.getLogger();
logger.info(“Hello logger”);
logger.info(MarketPlace | Object ${request.object});

//checking for the confirmation status
if (confirmed) {
//getting the moralis active Item table
const ActiveItem = Moralis.Object.extend(“ActiveItem”);
const query = new Moralis.Query(ActiveItem);

// getting the table data
query.equalTo("marketplaceAddress", request.object.get("address"));
query.equalTo("nftAddress", request.object.get("nftAddress"));
query.equalTo("tokenId", request.object.get("tokenId"));

logger.info(`MarketPlace | Query:${query}`);
// getting the first item that matches the search query
const canceledItem = await query.first();

logger.info(`MarketPlace | CanceledItem: ${canceledItem}`);
if (canceledItem) {
  logger.info(
    `Deleting ${request.object.get(
      "tokenId"
    )} at address${request.object.get("address")} since it was canceled`
  );

  await canceledItem.destroy();
} else {
  logger.info(
    `No item was found with address ${request.object.get(
      "address"
    )} and tokenId:${request.object.get("tokenId")}`
  );
}

}
});``

bought functions work, but the logger function on the ItemCanceled isnt working

Can you edit the code as per this so it will be easy to read?

And do you have any other errors related to ItemCanceled in database logs?

Moralis.Cloud.afterSave("SongListed", async (request) => {

  const confirmed = request.object.get("confirmed");

  const logger = Moralis.Cloud.getLogger();

  logger.info("looking for the confirmed tx..");

  //checking if thre item has beeen confirmed/listed

  if (confirmed) {

    logger.info("Found item...");

    //checking if ActiveItem existed and if not, create it

    const ActiveItem = Moralis.Object.extend("ActiveItem");

    const query = Moralis.Cloud.Query("ActiveItem");

    query.equalTo("marketplaceAddress", request.object.get("address"));

    query.equalTo("nftAddress", request.object.get("nftAddress"));

    query.equalTo("tokenId", request.object.get("tokenId"));

    query.equalTo("seller", request.object.get("seller"));

    const alreadyListed = await query.first();

    if (alreadyListed) {

      logger.info(`Deleting already listed ${request.object.get("objectID")}`);

      await alreadyListed.destroy();

      logger.info(

        `Deleted item already Listed with token id ${request.object.get(

          "tokenId"

        )} at address${request.object.get("address")} since its already listed`

      );

    }

    const activeItem = new ActiveItem();

    activeItem.set("marketplaceAddress", request.object.get("address"));

    activeItem.set("nftAddress", request.object.get("nftAddress"));

    activeItem.set("price", request.object.get("price"));

    activeItem.set("tokenId", request.object.get("tokenId"));

    activeItem.set("seller", request.object.get("seller"));

    logger.info(

      `Adding Address ${request.object.get(

        "address"

      )}. TokenID:${request.object.get("tokenId")}}`

    );

    logger.info("saving...");

    await activeItem.save();

  }

});

Moralis.Cloud.afterSave("ItemCanceled", async (request) => {

  //getting the confirm status from the moralis serveer

  const confirmed = request.object.get("confirmed");

  const logger = Moralis.Cloud.getLogger();

  logger.info("Hello logger");

  logger.info(`MarketPlace | Object ${request.object}`);

  //checking for the confirmation status

  if (confirmed) {

    //getting the moralis active Item table

    const ActiveItem = Moralis.Object.extend("ActiveItem");

    const query = new Moralis.Query(ActiveItem);

    // getting the table data

    query.equalTo("marketplaceAddress", request.object.get("address"));

    query.equalTo("nftAddress", request.object.get("nftAddress"));

    query.equalTo("tokenId", request.object.get("tokenId"));

    logger.info(`MarketPlace | Query:${query}`);

    // getting the first item that matches the search query

    const canceledItem = await query.first();

    logger.info(`MarketPlace | CanceledItem: ${canceledItem}`);

    if (canceledItem) {

      logger.info(

        `Deleting ${request.object.get(

          "tokenId"

        )} at address${request.object.get("address")} since it was canceled`

      );

      await canceledItem.destroy();

    } else {

      logger.info(

        `No item was found with address ${request.object.get(

          "address"

        )} and tokenId:${request.object.get("tokenId")}`

      );

    }

  }

});

I got no output on my logger from the ItemCanceled function just the SongListed

Your function seems right.
Are there any new items getting added to the ItemCanceled class?

No, I want the ItemCancel table to be populated with the canceled item, instead, the Item is destroyed and added back to the ActiveItem table, and I get no logger output from the second function just the first one

So there are no new columns getting added to ItemCanceled right?

afterSave on ItemCanceled will only trigger when a new row is saved.