question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Buffer.from doesn't allow "null" chunk

See original GitHub issue

What is the expected behavior? no error

What is the actual behavior? In some case, an error is Throw :

    TypeError : The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received null 
     TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received null
        at Function.from (buffer.js:313:9)
        [...]

Possible solution here you check if typeof chunk !== 'undefined', but typeof null === 'object' . So, the chunk pass in recordChunk, and recordChunk try to do Buffer.from(chunk, [...]), and chunk is null.

How to reproduce the issue I doesn’t know how I produce it (for the moment), but It seems to be a little check

Having problem producing a test case? Try and ask the community for help. If the test case cannot be reproduced, the Nock community might not be able to help you.

Does the bug have a test case? no Versions

Software Version(s)
Nock 12.0.2
Node 13.8.0
TypeScript 3.8.3

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
thib3113commented, Mar 7, 2020

@mastermatt as I say, running my test alone doesn’t produce the error, the error is only throw when I run all my tests … ( and, it doesn’t throw the error last time )

So, I’ll need to do some search to find what is really the problem, and why I receive null here … I will try some things to find the error when back at work (monday)

1reaction
mastermattcommented, Mar 7, 2020

Are you calling request.write(null) before request.end()? I’m able to get the same error by doing that, but that is not a valid call.

If request.write(null) is called, without Nock in the mix, you get the following error from this check in Node.

TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string or Buffer. Received type object

So when Nock is in record mode, the error messaging is slightly different, however, erring in general is the correct action. @thib3113 can you confirm if you’re getting this error another way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error writing to nodejs socket (TypeError: Invalid data, chunk ...
As is said in error, chunk can be only type string or buffer. So we have few solutions for your problem. First one,...
Read more >
Buffer | Node.js v19.3.0 Documentation
When decoding a Buffer into a string that does not exclusively contain valid UTF-8 data, the Unicode replacement character U+FFFD will...
Read more >
buffer
The Buffer class is a subclass of JavaScript's Uint8Array class and extends it with methods that cover additional use cases. Node.js APIs accept...
Read more >
Buffer Object - OpenGL Wiki
Immutable storage buffer objects allow you to establish a contract with OpenGL, specifying how you will access and modify the contents of ...
Read more >
new Buffer(size) : nodejs API - GitHub Pages
'ascii' - for 7 bit ASCII data only. This encoding method is very fast, and will strip the high bit if set. Note...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found