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

[fix] seralization error of BigInt does not throw an exception #1769

Closed
3 tasks done
conneryn opened this issue May 29, 2023 · 3 comments
Closed
3 tasks done

[fix] seralization error of BigInt does not throw an exception #1769

conneryn opened this issue May 29, 2023 · 3 comments
Labels

Comments

@conneryn
Copy link

Describe the bug

Node.js version: v16.14.0
OS version: Ubuntu 18.04.6 LTS
Description:

When attempting to send a POST request with a payload that contains a BigInt value, the JSON serialization silently fails and proceeds with the post request using a POST body set to: "[unable to serialize, circular reference is too complex to analyze]"

NOTE: I have not tested or checked if other serialization issues (ex: an actual circular reference) also have this same behaviour, but I imagine they very likely could.

Actual behavior

Superagent fails to serialize the BigInt to JSON, but instead of throwing an error, it simply continues to processes the POST request with the POST body set to: "[unable to serialize, circular reference is too complex to analyze]"

Expected behavior

Ideally, superagent would properly handle BigInt numbers... but at the very least it should:

  1. throw an exception when it fails to serialize data, and
  2. have an error message that is more accurate to the issue (ex: "Cannot serialize BigInt value" rather than a confusing message about circular references).

Code to reproduce

const superagent = require("superagent");
const data = {
    number: BigInt("1")
};

superagent
    .post("https://httpbin.org/post")
    .send(data)
    .end((err, res) => {
        console.log("ERROR:", err);
        console.log("POST BODY SENT TO SERVER:", res.body.data);
    });

Result:

ERROR: null
POST BODY SENT TO SERVER: "[unable to serialize, circular reference is too complex to analyze]"

Checklist

  • I have searched through GitHub issues for similar issues.
  • I have completely read through the README and documentation.
  • I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.
@NikoRaisanen
Copy link
Contributor

Just put up a PR for that issue here #1773

@titanism
Copy link
Collaborator

Closed per #1773

@titanism
Copy link
Collaborator

v8.1.0 released which fixes this issue, thank you

npm install superagent@8.1.0

release notes @ https://github.com/ladjs/superagent/releases/tag/v8.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants