Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetching server causes a "maximum call stack size exceeded" error #25

Open
kivox opened this issue May 12, 2023 · 8 comments
Open

Fetching server causes a "maximum call stack size exceeded" error #25

kivox opened this issue May 12, 2023 · 8 comments
Labels
bug Something isn't working

Comments

@kivox
Copy link

kivox commented May 12, 2023

When used in NextJS's API Handlers

import { type NextApiRequest, type NextApiResponse } from "next";
import { pteroAdmin } from "~/server/pterodactyl";

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
  return res.status(200).json(await pteroAdmin.servers.fetch("test"));
};

export default handler;

Issue is specific to NextJS, same does not occur when Node alone is used.

const { PteroApp } = require("@devnote-dev/pterojs");

const pteroAdmin = new PteroApp(
  "https://panel.",
  ""
);

pteroAdmin.servers
  .fetch("test")
  .then((servers) => {
    console.log(servers);
  })
  .catch((error) => {
    console.error(error);
  });

The issue seems to stem from the function "toSnakeCase"

error - Error [RangeError]: Maximum call stack size exceeded
    at toSnakeCase (file:///home/.../node_modules/@devnote-dev/pterojs/dist/index.mjs:300:21)
    at toSnakeCase (file:///home/.../node_modules/@devnote-dev/pterojs/dist/index.mjs:323:11)
    at toSnakeCase (file:///home/.../node_modules/@devnote-dev/pterojs/dist/index.mjs:323:11)
    ...
    digest: undefined
}
@devnote-dev
Copy link
Member

How many servers do you have on your panel? Keep in mind that #fetchAll is recursive and will attempt to cycle through every page of servers available.

@devnote-dev devnote-dev added the bug Something isn't working label May 12, 2023
@kivox
Copy link
Author

kivox commented May 13, 2023

How many servers do you have on your panel? Keep in mind that #fetchAll is recursive and will attempt to cycle through every page of servers available.

I've only got about 20 servers on the panel, so it shouldn't really be an issue. I have a feeling webpack or some of the underlying NextJS code might be at fault, as normal js works perfectly fine.

@WavingCatDevs
Copy link

I am also getting this issue also with Express. I haven't got many servers.

@kivox
Copy link
Author

kivox commented May 14, 2023

Some additional info

Attempted to fix it, but it's not the correct fix, it's an issue with the conversion of the object to JSON.

import { type NextApiRequest, type NextApiResponse } from "next";
import { pteroAdmin } from "~/server/pterodactyl";

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
  const server = await pteroAdmin.servers.fetch("test");

  return res.status(200).json(server);
};

export default handler;

Same error occurs with res.status(200).json(server.toJSON());, but when I use server.id instead of just server it works fine.

@kivox
Copy link
Author

kivox commented May 14, 2023

.toJSON() is also affected. console.log(server) works but console.log(server.toJSON()); doesn't

@kivox
Copy link
Author

kivox commented May 14, 2023

const pteroSrv = await ctx.pteroAdmin.servers.fetch(srv.id);

return {
   ...server
}

Causes the following error

Converting circular structure to JSON
    --> starting at object with constructor 'PteroApp'
    |     property 'allocations' -> object with constructor 'NodeAllocationManager'
    --- property 'client' closes the circle

Using the library built-in toJSON causes Maximum call stack size exceeded

@devnote-dev
Copy link
Member

It looks like there's still objects in the ApplicationServer class that the case conversion functions are trying to handle which are evidently circularly-referenced, hence the recursion issues. I'll need to do more debugging into it to see what fields cause it though.

@FC5570
Copy link

FC5570 commented May 18, 2023

I've had this same issue. Try deleting the database property from the ApplicationServer object and then calling .toJSON()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants