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

Got throws if passed options are already frozen #1050

Closed
2 tasks done
gautaz opened this issue Feb 6, 2020 · 0 comments · Fixed by #1051
Closed
2 tasks done

Got throws if passed options are already frozen #1050

gautaz opened this issue Feb 6, 2020 · 0 comments · Fixed by #1051
Labels
bug Something does not work as it should ✭ help wanted ✭

Comments

@gautaz
Copy link

gautaz commented Feb 6, 2020

Describe the bug

Currently the snippet provided in the code to reproduce section fails.

got tries to mutate the options object. This currently impacts test scenarii where the same options object is used between different tests.

Actual behavior

> node .

(node:12424) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'body' of undefined
    at /home/user/dev/got-issue/index.js:12:32
(node:12424) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:12424) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Expected behavior

No mutation.

Code to reproduce

const got = require('got');
const options = {};

Object.freeze(options);

(async () => {
  try {
    const response = await got('https://sindresorhus.com', options);
    console.log(response.body);
    //=> '<!doctype html> ...'
  } catch (error) {
    console.log(error.response.body);
    //=> 'Internal server error ...'
  }
})();

Checklist

  • I have read the documentation.
  • I have tried my code with the latest version of Node.js and Got.
@szmarczak szmarczak changed the title got should not mutate options Got throws if passed options are already frozen Feb 6, 2020
@szmarczak szmarczak added bug Something does not work as it should ✭ help wanted ✭ labels Feb 6, 2020
@szmarczak szmarczak mentioned this issue Feb 6, 2020
18 tasks
szmarczak added a commit to szmarczak/got that referenced this issue Feb 29, 2020
szmarczak added a commit to szmarczak/got that referenced this issue Mar 3, 2020
szmarczak added a commit to szmarczak/got that referenced this issue Mar 4, 2020
@mpern mpern mentioned this issue Mar 21, 2020
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something does not work as it should ✭ help wanted ✭
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants