Error: toString failed Node.js buffer - node.js

Sometimes my get request to an api fails with this error message, (btw im using the request module to trigger my requests)
Error: toString failed
buffer.js:378
throw new Error('toString failed');
^
Error: toString failed
at Buffer.toString (buffer.js:378:11)
at BufferList.toString (/home/vardha/www/abp/node_modules/bl/bl.js:155:33)
at Request.<anonymous> (/home/vardha/www/abp/node_modules/request/request.js:1013:32)
at emitOne (events.js:82:20)
at Request.emit (events.js:169:7)
at IncomingMessage.<anonymous> (/home/vardha/www/abp/node_modules/request/request.js:962:12)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:921:12)
at nextTickCallbackWith2Args (node.js:442:9)
This has been buggin me a lot since I have no idea as to whats causing this and was not able to find any clear solution in the github page. ANy help would be appreciated.

This error usually occurs when you request for file which is relatively bigger in size (or) the bufferlength exceeds / reaches 256 MB which the V8 engine will throw as an error.
This issue is still being addressed by the NodeJS community Read out this comprehensive post which has all the progress/answers that you are looking for.
https://github.com/nodejs/node/pull/4394
Hope this helps!

Related

Jasmine test suite doesn't run

I can't figure out what I've done to mess up Jasmine.
Here's a link to the repo I'm working on:
https://github.com/bryanbeus/04-09-bloccit/tree/v0.1.3
The problem is somehow related to the files /spec/integration/flairs_spec.js, /spec/integration/post_spec.js, and probably more.
The problem can be seen when running a command like npm test. I get the following result:
04-09-bloccit#1.0.0 test /home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit
export NODE_ENV=test && jasmine
npm ERR! Test failed. See above for more details.
It used to be that this ERR would only occur if I had an non-compilable error somewhere in my code. (For example, a simple thing like ; out of place, or an improper use of this.)
Recently, I've heard from someone else that this type of failure for Jasmine isn't normal. Usually, if there's a problem in the code, Jasmine is still supposed to say something. ?
Whatever the problem is, it is now spreading to general usage.
I'm trying to call the server npm module for a test with this command:
const server = require("../../src/server");
If that line is anywhere in my files, the entire Jasmine test fails in the exact same manner. (npm ERR... and no other details.)
If I run npm test /spec/integration/flairs_spec.js with that call to server active, the test fails in the npm ERR... manner.
However, if I comment out the call to server, then Jasmine at least runs. It returns this error:
....................
Started
F
Failures:
1) routes : flairs GET /topics/:topicId/posts/:postId/flairs/new should render a new flair form
Message:
Expected Error: connect ECONNREFUSED 127.0.0.1:3000 to be null.
Stack:
Error: Expected Error: connect ECONNREFUSED 127.0.0.1:3000 to be null.
at
at Request.request.get [as _callback] (/home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit/spec/integration/flairs_spec.js:57:21)
at self.callback (/home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit/node_modules/request/request.js:186:22)
at Request.emit (events.js:160:13)
at Request.onRequestError (/home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit/node_modules/request/request.js:878:8)
at ClientRequest.emit (events.js:160:13)
at Socket.socketErrorListener (_http_client.js:389:9)
at Socket.emit (events.js:160:13)
at emitErrorNT (internal/streams/destroy.js:64:8)
at process._tickCallback (internal/process/next_tick.js:152:19)
Message:
Expected undefined to contain 'New Flair'.
Stack:
Error: Expected undefined to contain 'New Flair'.
at
at Request.request.get [as _callback] (/home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit/spec/integration/flairs_spec.js:58:22)
at self.callback (/home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit/node_modules/request/request.js:186:22)
at Request.emit (events.js:160:13)
at Request.onRequestError (/home/siddhartha/Documents/07-Temp/01-Bloc/04-09-bloccit/node_modules/request/request.js:878:8)
at ClientRequest.emit (events.js:160:13)
at Socket.socketErrorListener (_http_client.js:389:9)
at Socket.emit (events.js:160:13)
at emitErrorNT (internal/streams/destroy.js:64:8)
at process._tickCallback (internal/process/next_tick.js:152:19)
1 spec, 1 failure
Finished in 0.399 seconds
npm ERR! Test failed. See above for more details.
.......
So, removing the server call at least lets Jasmine run.
Any help on this is appreciated. Thank you for helping a novice programmer.
I found the source of the error.
Using git diff v0.1.2..v0.1.3 I was able to see the differences between the last working branch, and the current one.
From here, I saw that in db/src/controllers/flairController.js I had placed this in the controller for the flair object:
const flairQueries = require("./db/queries.flairs.js");
The problem with that is that the directory isn't correct. I replaced it with this:
const flairQueries = require("../db/queries.flairs.js");
After this, the Jasmine test suite worked.
I understand that this means that the controller couldn't load properly. The full understanding of this is still elusive, so if anyone has time to try to explain, I would appreciate it. Otherwise, we can consider this question closed. Thanks!

Error while trying to retrieve access token

In My project with Google calendar api getting error message when trying to authenticate using the code that given by the url
https://accounts.google.com/o/oauth2/auth?access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcalendar.readonly&response_type=code&client_id=353577961315-njban7i0ach9ditqeojomv18lmqlcglp.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A4200
Error message
Error while trying to retrieve access token { Error: invalid_grant
at Request._callback (C:\Users\PC\Desktop\New folder\node_modules\google-auth-library\lib\transporters.js:81:15)
at Request.self.callback (C:\Users\PC\Desktop\New folder\node_modules\request\request.js:188:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request. (C:\Users\PC\Desktop\New folder\node_modules\request\request.js:1171:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage. (C:\Users\PC\Desktop\New folder\node_modules\request\request.js:1091:12)
at IncomingMessage.g (events.js:292:16)
at emitNone (events.js:91:20) code: 400 }
What the reason for getting the error message and how can i resolve this issue?
There are 2 common problems that cause invalid_grant errors:
Your server's clock is out of sync with NTP
You've exceeded the refresh token limit
I'd suggest investigating whether either of these issues could be the source of your problem.

Upload a file to Autodesk Forge - ESOCKETTIMEDOUT error

I am new to Autodesk-Forge API and I am trying to use the sample dmSample.js, included in the node.js SDK.
The example works well for very small files (up to 500 Kb)
However, when I try to upload larger files, (even just 1 Mb), the execution stops after few seconds with the following error message :
Error: { Error: ESOCKETTIMEDOUT
at ClientRequest.<anonymous> (C:\node.js dev\forge-api-nodejs-client node_mo dules\request\request.js:819:19)
at ClientRequest.g (events.js:292:16)
at emitNone (events.js:86:13)
at ClientRequest.emit (events.js:185:7)
at TLSSocket.emitTimeout (_http_client.js:629:10)
at TLSSocket.g (events.js:292:16)
at emitNone (events.js:86:13)
at TLSSocket.emit (events.js:185:7)
at TLSSocket.Socket._onTimeout (net.js:338:8)
at ontimeout (timers.js:386:14) code: 'ESOCKETTIMEDOUT', connect: false
}
The file I am trying to upload is 30 Mb and is on my local post.
Any idea ?
I was able to fix it by increasing the value of the timeout of the request module.
Forge uses a wrapper that it is located in
/src/ApiClient.js
Search for this.timeout and set it to something like.
this.timeout = 600000;

node.js post causes error

I am running this app. https://github.com/azat-co/practicalnode
chapter 5- blog-express app.
the only change is twitter consumer key and secret I made in app.js file
I can run this app and sign-in with twitter.
But when I try to post an article it causes error.
Connect
400 Error: request size did not match content length
at makeError (/home/myname/Documents/nodejs/practicalnode/ch7/blog-express/node_modules/body-parser/node_modules/raw-body/index.js:136:15)
at IncomingMessage.onEnd (/home/myname/Documents/nodejs/practicalnode/ch7/blog-express/node_modules/body-parser/node_modules/raw-body/index.js:106:13)
at IncomingMessage.g (events.js:180:16)
at IncomingMessage.emit (events.js:92:17)
at _stream_readable.js:938:16
at process._tickCallback (node.js:419:13)
What should I check?what could be wrong.
thanks

Strange error in production with node.js and nginx: "Error: Request aborted"

I really don't know what is happening but the request is aborted at some time and only happens in production on the unix machine. On my windows machine works everything fine.
I'm using express and express.bodyParser. There is many things that it depends, so ask me what I need to provide in order to help me.
Error:
Error: Request aborted
at IncomingMessage.onReqAborted (/var/apps/xxx/node_modules/easy-express/node_modules/express/node_modules/connect/node_modules/multiparty/index.js:131:17)
at IncomingMessage.EventEmitter.emit (events.js:92:17)
at abortIncoming (http.js:1912:11)
at Socket.socket.onend (http.js:2004:7)
at Socket.g (events.js:175:14)
at Socket.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:920:16
at process._tickCallback (node.js:415:13)
Here I've seen this https://github.com/andrewrk/node-multiparty:
'aborted'
Emitted when the request is aborted. This event will be followed shortly by an error event. In practice you do not need to handle this event.
What is strange is that it works. The only problem is the error in the log really. I think it might have other problems.
Thanks (:

Resources