nock: Buffer.from doesn't allow "null" chunk
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 |
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (6 by maintainers)
@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.