CLI Deploy returns 500 error for Functions

Hi! I am using Netlify functions with Eleventy using Zach Leatherman’s eleventy-serverless-oauth. Recently, authentification with Functions stopped with this error being displayed on the website:

{
  "error": "json.filter is not a function"
}

This is the console error log:

Request from ::1: GET /.netlify/functions/auth-callback?code=2bb03706b0e64019bbadb5b8d67f2bcbb81120fc&state=url%3Dhttp%3A%2F%2Flocalhost%3A8888%2Fsecure%2F%26csrf%3D76c14a00-366a-467a-b060-0960a9975e1a%26provider%3Dtodoist
[auth-callback] Access Token Error argument str must be a string
[auth-callback] TypeError: argument str must be a string
    at Object.parse (/Users/Joschua/Documents/Projects/todoist-focus-mode/node_modules/cookie/index.js:49:11)
    at Object.exports.handler (/Users/Joschua/Documents/Projects/todoist-focus-mode/netlify/functions/auth-callback.js:25:26)
    at Object._executeSync (/Users/Joschua/Documents/Projects/todoist-focus-mode/node_modules/netlify-cli/node_modules/lambda-local/build/lambdalocal.js:295:47)
    at /Users/Joschua/Documents/Projects/todoist-focus-mode/node_modules/netlify-cli/node_modules/lambda-local/build/lambdalocal.js:95:26
    at new Promise (<anonymous>)
    at Object.execute (/Users/Joschua/Documents/Projects/todoist-focus-mode/node_modules/netlify-cli/node_modules/lambda-local/build/lambdalocal.js:87:16)
    at Object.invokeFunction (/Users/Joschua/Documents/Projects/todoist-focus-mode/node_modules/netlify-cli/src/lib/functions/runtimes/js/index.cjs:58:36)
    at NetlifyFunction.invoke (/Users/Joschua/Documents/Projects/todoist-focus-mode/node_modules/netlify-cli/src/lib/functions/netlify-function.cjs:123:41)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async handler (/Users/Joschua/Documents/Projects/todoist-focus-mode/node_modules/netlify-cli/src/lib/functions/server.cjs:154:33)
Response with status 500 in 10 ms.

When inspecting the code, it seems like Cookies somehow can’t be set. This is the line that is relevant:

The strange thing is that it just stopped working out of the blue. I reverted my code back to when it worked but I still get a 500 error. When deploying through netlify deploy on the command line I get this error:

Deploy path:        /Users/Joschua/Documents/Projects/todoist-focus-mode/_site
Functions path:     /Users/Joschua/Documents/Projects/todoist-focus-mode/netlify/functions
Configuration path: /Users/Joschua/Documents/Projects/todoist-focus-mode/netlify.toml
Deploying to draft URL...
✔ Ignored invalid or expired functions cache
✔ Finished hashing 42 files and 3 functions
✔ CDN requesting 21 files and 3 functions
⠴ (23/24) Uploading dynamic... ›   Warning: JSONHTTPError:  500
 ›   Warning: 
{
  "name": "JSONHTTPError",
  "status": 500,
  "json": {
    "status": 500,
    "error": "Internal Server Error"
  }
}

 ›   JSONHTTPError: Internal Server Error

Seems like there is an issue with the function on Netlify’s server side.

I’ve been investigating for hours but am stuck. I’d really appreciate your help!

Is there an easy way for us to be able to reproduce this? At the moment, I can see, we need to sign up with Todoist, and then use that to login here, just wondering if there’s any other way to check this without having to do that.

Could you explain how you got to that conclusion? What did you test that made you think so? Because the line that you’re highlighting seems to be parsing cookies, not setting. I am assuming the cookies are not being parsed because they aren’t set, but did you try checking for the presence of cookies before trying to parse them?

Lastly, does this happen only when deploying from CLI or also happens with deploying from a Git repo?

1 Like

Thanks for coming back to me. I appreciate your time!

#1 Todoist login

Yeah, the website requires authentification with Todoist. That’s presumably also where the error appears so I can’t remove it for easier reproduction. However, I set up a Todoist account for you to simply log in to. I sent the account details via DM.

#2 Setting cookies

The error message from above lists the following error:

At line 25 is the function that parses the cookie from the request headers (the line highlighted in the source code). A console.log of event.headers.cookie returns undefined. This leads me to believe that the cookies aren’t set properly.

As mentioned, the strange thing is that this stopped working suddenly. It seems that after adding a custom domain in Netlify, the error appeared but my timeline might also be off.

#3: Deployment

The error occurs both in deploying from the CLI and deploying from a Git repo. Deploying from the CLI throws an error. Deploying via Git doesn’t give an error but the functionality on the website itself is still broken.

Thanks for the credentials @selfire1, unfortunately I cannot test it (reliably) either in the production version or in the local version.

The production version seems to redirect back to localhost:8888, and the local version cannot run because I don’t have your environment variables.

However, I tried keeping the local server running and used the production app to redirect back to the locahost version. The function does fail where you say it fails, but as far as I can see, the cookie is being set correctly:

Now why it’s still not being used, I can only answer once I can test your site either on the production URL or the localhost version completely.

1 Like

Thanks for your effort to test the version. Sorry about the env variables, should have had that in mind. I created a production and a local development version of the Auth provider. I’ll sent through the env variables for local development.

Interesting about the cookie being set correctly, I am still debugging as well and curious about where the bug lies in the end.

Hey @selfire1,

As mentioned in the DM, the credentials don’t seem to work for me.

I tried with the updated environment variables and it seems to work fine locally. The only way I was able to see the problem was, once I got to this page:

cleared the cookies, and refreshed the page. That’s when I saw:

{
  "error": "json.filter is not a function"
}

which is probably expected as there were no cookies. But other than that, I have not been able to reproduce this issue.

I did see the problem on the production version though. But even there, I can see the cookie is being set and used:

So why it’s still failing, I can’t say for sure. I did find this though: