Function log hanging forever

here is my code:

const {getSubscriptions, getResponse} = require('./utils/utils.js');

module.exports.handler = async function(event, context) {

    

    const allItems = await getSubscriptions();

    

    if (!allItems) {

        return getResponse(204, "");

    }

    console.log('showCache is called', allItems);

    const subscriptions = allItems.map(item => item.data);

    const result = JSON.stringify(subscriptions);

    console.log('-------------result----------', result);

     return getResponse(200, result);

}

const getSubscriptions = async () => {

  try {

    const response = await client.query(

      q.Paginate(q.Match(q.Ref("indexes/all_subs")))

    );

    console.log("---response---", response);

    const subsRefs = response.data;

    if (!subsRefs) {

      return null;

    }

    console.log(`${subsRefs.length} subscription found`);

    const getAllSubsQuery = subsRefs.map((ref) => q.Get(ref));

    const allSubscriptions = await client.query(getAllSubsQuery);

    console.log("---------getSubsFinal-------", allSubscriptions);

    return allSubscriptions;

  } catch (faunaDBError) {

    console.log("----getSubscriptions error----", faunaDBError);

    return null;

  }

};

const faunadb = require("faunadb");

const q = faunadb.query;

const client = new faunadb.Client({

  secret: process.env.FAUNADB_SERVER_SECRET,

});

const headers = {

  'Access-Control-Allow-Origin': '*',

  'Access-Control-Allow-Headers': 'Content-Type',

  'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE'

};

function getResponse(statusCode, body) {

  return {

    statusCode: statusCode,

    headers,

    body: body,

  };

}

I searched a while and found similar questions but they are caused by not waiting for async function.
From my code, I think I have await everywhere it needs.

Please help.

Hey @franva,
Debugging your code is a bit beyond what we’re able to offer in this forum, but one way to test that the connection between your site and your function is working would be to deploy a simple logging function like:

// does-it-work.js
exports.handler = async function(event, context) {
    console.log(JSON.parse(event.body))
    return {
      status: 200
    };
};

and then hit the function endpoint. You should see the event log there. Let us know if that’s not the case!

For Netlify and Fauna DB together, there’s a nice (if a little outdated) demo here:

I do have logs in my functions.

My understanding was once I opened a Function Log page, I would be able to see logs since the current master branch deployed.

But it seems that after I opened the Function Log page, I have to make at least one call to the api in order to see logs(even I have made several api calls already before opening the Function Log page), which is not intuitive.

Not sure whether this is the fix, but at least I start seeing logs now.

Ah, yeah, that’s currently the intended behavior of our logs- not a bug. Glad to hear you are seeing logs after calling the endpoint now.

thanks for confirming it.

Just 1 suggestion. If that’s the current intent behavior, could we remove the spinning slash?

It might look unimportant, but it creates huge confusion for many people, once you searched StackOverFlow, you would see many people asking the same question.

The spinning slash to me means: hang on there, I have something to show you in a few seconds.

So that’s why we thought we would be able to see logs since the current deployment.

Looks like we have an open feature request internally for this- I added your +1 there!

1 Like