Buffer.from doesn't allow "null" chunk
See original GitHub issueWhat 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:
- Created 4 years ago
- Comments:17 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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)
Are you calling
request.write(null)
beforerequest.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.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.