Vague error messages in functions

I am trying to use the Apollo client in my functions, and the creation of a client variable is throwing an error, but it just gives messages like

Invariant Violation: Invariant Violation: 1 (see https://github.com/apollographql/invariant-packages)
at new t (/var/www/html/cartoonistdb-frontend/built-lambda/send_contact_email.js:16:80875)
at /var/www/html/cartoonistdb-frontend/built-lambda/send_contact_email.js:16:82225
at jt (/var/www/html/cartoonistdb-frontend/built-lambda/send_contact_email.js:16:82235)
at new t (/var/www/html/cartoonistdb-frontend/built-lambda/send_contact_email.js:16:85135)
at new t (/var/www/html/cartoonistdb-frontend/built-lambda/send_contact_email.js:16:86965)
at Object.exports.handler (/var/www/html/cartoonistdb-frontend/built-lambda/send_contact_email.js:16:87513)
at /var/www/html/cartoonistdb-frontend/node_modules/netlify-lambda/lib/serve.js:133:27

I checked with the Apollo docs and they say it’s shortening the error messaging because it’s running from a production environment (which it isn’t, I’m testing the function locally), so I’m not sure what I can do to get more verbose error messaging. Any help would be appreciated!

Hmm, I haven’t seen that error message before, and I do believe that it comes from some of your code even if not intended by you - rather than something from our system which would be more likely to say “module not found” or something similarly pointing to “how function was created” rather than “how function runs” - once it’s to running, generally, that’s in your code if it fails. It looks from the stack trace like you’re using netlify-lambda serve to test and seeing that - could you confirm?

Regardless, I’d suggest figuring out how to convince Apollo that your environment isn’t production to get the full error message :slight_smile: Maybe it’s as easy as setting NODE_ENV to development? Not sure as I don’t use Apollo but that’d be where I’d start debugging from here.

It looks from the stack trace like you’re using netlify-lambda serve to test and seeing that - could you confirm? Any chance you can share your

Yes, I’m using netlify-lambda serve to test. My function is super simple at this point. The error is coming from trying to create a new ApolloClient object (since that’s virtually all that’s happening in the function at the moment).

import ApolloClient from “apollo-boost”;
import gql from “graphql-tag”;

exports.handler = function(event, context, callback) {
const creator = event.queryStringParameters.creator_id;

if(creator === undefined || creator === null){
    callback(null, {
        statusCode: 404,
        body: JSON.stringify({ 
            statusCode: 404,
            msg: "Creator not found"
        })
    });
}

getCreatorEmail(creator);

callback(null, {
    statusCode: 200,
    body: JSON.stringify({ 
        statusCode: 200,
        msg: "Email sent successfully."
    })
});

}

function getCreatorEmail(id){

const client = new ApolloClient({
    uri: "https://path/to/graphql/api",
    headers: {
    }
    
});

}

Hi @cameronrdecker can you set process.env.NODE_ENV to development when you run the function and then check the contents of the error? Thanks.

Thanks, @futuregerald! I’m having trouble figuring out where to set the NODE_ENV environment variable. I’ve set it in the .env file for my overall project (which the function doesn’t seem to have access to), and I set it in my netlify.toml file and no luck there either. Is there another place I should be setting it?

Nevermind, I got it set! in my package.json file I had to add the variable in the start command:

"scripts": {
"start": "react-scripts start",
"start:lambda": "NODE_ENV=development netlify-lambda serve src/lambda",
"build": "react-scripts build",
"build:lambda": "netlify-lambda build src/lambda",
"test": "react-scripts test",
"eject": "react-scripts eject"
},

This change did make the error handling more verbose, so thanks for your help!