Neo4j's NPM component blows up without error - node.js

I'm using the thingdom/node-neo4j module like this:
var neo = require('neo4j');
var db = new new.GraphDatabase(...);
but when I call the cypher method with some invalid script, instead of returning an error (allowing me to handle it), it blows up:
db.cypher('// invalid cypher script', (err, res) => {
if (err) console.log('ERROR: ' + err);
console.log(res);
})
what I get is a stack trace that looks like this:
/Users/ekkis/dev/test/inc/node_modules/neo4j/lib-new/errors.js:20
Error.captureStackTrace(this, this.constructor);
^
TypeError: Error.captureStackTrace is not a function
at ClientError.Error [as constructor] (/Users/ekkis/dev/test/inc/node_modules/neo4j/lib-new/errors.js:20:13)
at new ClientError (/Users/ekkis/dev/test/inc/node_modules/neo4j/lib-new/errors.js:81:48)
at Function.__dirname.Error.Error._fromObject (/Users/ekkis/dev/test/inc/node_modules/neo4j/lib-new/errors.js:70:14)
at /Users/ekkis/dev/test/inc/node_modules/neo4j/lib-new/GraphDatabase.js:302:25
at Request._callback (/Users/ekkis/dev/test/inc/node_modules/neo4j/lib-new/GraphDatabase.js:92:20)
at Request.self.callback (/Users/ekkis/dev/test/inc/node_modules/request/request.js:187:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request. (/Users/ekkis/dev/test/inc/node_modules/request/request.js:969:12)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
I'm using node v7.3.0 and posted an issue with the maintainer here: https://github.com/thingdom/node-neo4j/issues/214 but so far no solution. is anyone else running into this? any solutions?

Related

How to parse error parameter in request callback?

I'm deliberately triggering an error in a stored procedure under certain conditions which I want to catch in my Node.js API which uses the Tedious package.
Code Snippet from API:
let request = new Request(sql, (err)=>{
if (err) {
sqlerr = err;
console.log(typeof(err));
console.log("**RQ-ERROR**", err);
}
});
In the callback of the "Request" object above there is an "err" parameter. The "typeof()" returns "object"; however, when I dump it to the console it looks like this:
**RQ-ERROR** { RequestError: Duplicate entry for specified period
at RequestError (C:\inetpub\wwwroot\PersonnelApps\kudosapi\node_modules\tedious\lib\errors.js:32:12)
at Parser.tokenStreamParser.on.token (C:\inetpub\wwwroot\PersonnelApps\kudosapi\node_modules\tedious\lib\connection.js:723:34)
at emitOne (events.js:96:13)
at Parser.emit (events.js:188:7)
at Parser.parser.on.token (C:\inetpub\wwwroot\PersonnelApps\kudosapi\node_modules\tedious\lib\token\token-stream-parser.js:27:14)
at emitOne (events.js:96:13)
at Parser.emit (events.js:188:7)
at addChunk (C:\inetpub\wwwroot\PersonnelApps\kudosapi\node_modules\readable-stream\lib\_stream_readable.js:297:12)
at readableAddChunk (C:\inetpub\wwwroot\PersonnelApps\kudosapi\node_modules\readable-stream\lib\_stream_readable.js:279:11)
at Parser.Readable.push (C:\inetpub\wwwroot\PersonnelApps\kudosapi\node_modules\readable-stream\lib\_stream_readable.js:240:10)
message: 'Duplicate entry for specified period',
code: 'EREQUEST',
number: 50000,
state: 1,
class: 16,
serverName: 'PERSODG2LNN52\\SQLEXPRESS',
procName: 'CreateStatusReport',
lineNumber: 44 }
This almost looks like a JavaScript object but, as you can see, the "RequestError" data isn't quoted nor is there a comma after the text "240:10)" just before the "message" member. I'm not sure if this is a bug in TDS or if I'm just missing something but I cannot access any of the members as it is. I'd have to convert it to a string and parse it which is fine but isn't very elegant.
Suggestions?
as you can see, the "RequestError" data isn't quoted nor is there a comma after the text "240:10)"
These are artifacts of the console logging out the error message. You can try it out for yourself with something like the following:
$ node
> console.log(new Error('this is an error object!'));
Error: this is an error object!
at repl:1:13
at Script.runInThisContext (vm.js:119:20)
at REPLServer.defaultEval (repl.js:332:29)
at bound (domain.js:395:14)
at REPLServer.runBound [as eval] (domain.js:408:12)
at REPLServer.onLine (repl.js:639:10)
at REPLServer.emit (events.js:194:15)
at REPLServer.EventEmitter.emit (domain.js:441:20)
at REPLServer.Interface._onLine (readline.js:290:10)
at REPLServer.Interface._line (readline.js:638:8)
I'm not exactly sure what the desired outcome of this question is, but try inspecting the err.message property rather than using the typeof operator.

Getting the widths of a lot of images causes ENOTFOUND in Node.js

I have several sources of lists of images (flicker, images stored at s3, imgur, etc)
I want to get the dimenions of these images.
I use node and https://github.com/nodeca/probe-image-size to go over each url and use that to get the width of the image and count how many images are at a certain width via the following code
probes = [];
_.forEach(image_urls, url => {
probes.push(probe(url));
});
results = await Promise.all(probes);
_.forEach(results, result_of_image => {
width = parseInt(result_of_image.width / 10) * 10;
if (!widthes[width]) {
widthes[width] = 1;
} else {
widthes[width]++;
}
});
even though all urls are accessible, I sometimes get getaddrinfo ENOTFOUND with the stack
at ClientRequest.req.once.err (/image_script/node_modules/got/index.js:73:21)
at Object.onceWrapper (events.js:293:19)
at emitOne (events.js:101:20)
at ClientRequest.emit (events.js:191:7)
at TLSSocket.socketErrorListener (_http_client.js:358:9)
at emitOne (events.js:96:13)
at TLSSocket.emit (events.js:191:7)
at connectErrorNT (net.js:1031:8)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)
I suspect that because the url list is very large (in the thousands) that node just takes all resources of the system and things just stop working properly (this is a guess)
Is there a better way to do the above? or provide node with some connection pool?

Failed to launch renderer:Exception For HTML5 to PDF Convertor

I am using "html5-to-pdf" module to convert HTML5 page to PDF.Below is the code snippet I am using for specifying the Input and Output files.
var html5pdf = require("html5-to-pdf");
var fs = require("fs");
fs.createReadStream("/Vineet/POC/HTML_Inputs/TestSample.html")
.pipe(html5pdf())
.pipe(fs.createWriteStream("/Vineet/POC/PDF_Outputs/Output.pdf"));
While executing this code I am getting below exception:
Error: Failed to launch renderer
at C:\Vineet\POC\node_modules\html5-to-pdf\src\phantom.coffee:55:35
at Proto.apply (C:\Vineet\POC\node_modules\dnode-protocol\index.js:123:13)
at Proto.handle (C:\Vineet\POC\node_modules\dnode-protocol\index.js:99:19)
at D.dnode.handle (C:\Vineet\POC\node_modules\dnode\lib\dnode.js:140:21)
at D.dnode.write (C:\Vineet\POC\node_modules\dnode\lib\dnode.js:128:22)
at SockJSConnection.ondata (stream.js:31:26)
at emitOne (events.js:96:13)
at SockJSConnection.emit (events.js:188:7)
at Session.didMessage (C:\Vineet\POC\node_modules\sockjs\lib\transport.js:220:25)
at WebSocketReceiver.didMessage (C:\Vineet\POC\node_modules\sockjs\lib\trans-websocket.js:102:40)
at C:\Vineet\POC\node_modules\sockjs\lib\trans-websocket.js:75:22
at .<anonymous> (C:\Vineet\POC\node_modules\faye-websocket\lib\faye\websocket\api\event_target.js:41:7)
at Array.forEach (native)
at EventTarget.dispatchEvent (C:\Vineet\POC\node_modules\faye-websocket\lib\faye\websocket\api\event_target.js:40:33)
at API.receive (C:\Vineet\POC\node_modules\faye-websocket\lib\faye\websocket\api.js:30:10)
at instance._emitFrame (C:\Vineet\POC\node_modules\faye-websocket\lib\faye\websocket\hybi_parser.js:285:44)
at instance.parse (C:\Vineet\POC\node_modules\faye-websocket\lib\faye\websocket\hybi_parser.js:143:18)
at Socket.<anonymous> (C:\Vineet\POC\node_modules\faye-websocket\lib\faye\websocket.js:72:33)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:172:18)
at Socket.Readable.push (_stream_readable.js:130:10)
at TCP.onread (net.js:542:20)
Due to which The PDF generated is of 0 bytes and is not being able to open.CAn any one help me in resolving this issue.
This package need PhatomJS installed on your computer. Phantomjs renders the page and saves it to a PDF. Read html5-to-pdf options params
You should use html-pdf package instead.
var pdf = require('html-pdf'),
fs = require('fs');
pdf.create(fs.readFileSync('./Vineet/POC/HTML_Inputs/TestSample.html', 'utf8'), { format: 'Letter' }).toFile('./Vineet/POC/PDF_Outputs/Output.pdf', function(err, res) {
if (err) return console.log(err);
console.log(res);
});

bodyParse error suppression

I'm currently using bodyParser with Express to accept JSON requests. Whenever I pass in an incorrectly formed JSON object it returns a nasty error via the endpoint and logs it to the console as well. The following is the error:
SyntaxError: Unexpected string
at Object.parse (native)
at parse (/Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/lib/types/json.js:88:17)
at /Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/lib/read.js:108:18
at done (/Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/node_modules/raw-body/index.js:239:14)
at IncomingMessage.onEnd (/Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/node_modules/raw-body/index.js:285:7)
at IncomingMessage.g (events.js:199:16)
at IncomingMessage.emit (events.js:104:17)
at _stream_readable.js:908:16
at process._tickCallback (node.js:355:11)
SyntaxError: Unexpected string
at Object.parse (native)
at parse (/Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/lib/types/json.js:88:17)
at /Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/lib/read.js:108:18
at done (/Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/node_modules/raw-body/index.js:239:14)
at IncomingMessage.onEnd (/Users/ddibiase-mbp/Documents/Projects/theride_api/node_modules/body-parser/node_modules/raw-body/index.js:285:7)
at IncomingMessage.g (events.js:199:16)
at IncomingMessage.emit (events.js:104:17)
at _stream_readable.js:908:16
at process._tickCallback (node.js:355:11)
I'm wondering how I can suppress the error or patch this completely. I've investigated the error but can't find any specific recommendations for patching it.
It's common to declare an error handler with Express:
app.use(function(err, req, res, next) {
...
return res.sendStatus(500);
});
This will also catch errors thrown in middleware like body-parser.

Using compound, I got an error on update when using validatesPresenceOf

I'm creating an app with compound and mongodb. Compound use jugglingdb and jugglingdb-mongodb to connect to mongodb.
I generated a crud for a client using the scaffolding of compound. Then, I added Client.validatesPresenceOf('name'); to app/models/client.js
module.exports = function (compound, Client) {
Client.validatesPresenceOf('name');
};
On create, it work, but on update it fail.
I also tried adding the validation to db/schema.js, but I got the same error.
This is the error I got
/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/jugglingdb-mongodb/node_modules/mongodb/lib/mongodb/connection/server.js:529
throw err;
^
Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (http.js:708:11)
at ServerResponse.res.setHeader (/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/express/node_modules/connect/lib/patch.js:59:22)
at ServerResponse.res.set.res.header (/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/express/lib/response.js:518:10)
at ServerResponse.res.location (/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/express/lib/response.js:649:8)
at ServerResponse.res.redirect (/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/express/lib/response.js:691:8)
at Controller.Helpers.redirect (/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/compound/node_modules/kontroller/lib/helpers.js:168:14)
at eval (eval at (/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/compound/node_modules/kontroller/lib/base.js:157:17), :97:38)
at Object.html (/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/compound/node_modules/kontroller/lib/helpers.js:43:17)
at eval (eval at (/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/compound/node_modules/kontroller/lib/base.js:157:17), :93:20)
at Controller.respondTo (/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/compound/node_modules/kontroller/lib/helpers.js:38:5)
at action.cliente.destroy.format.json.send.code (eval at (/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/compound/node_modules/kontroller/lib/base.js:157:17), :84:9)
at ModelConstructor. (/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/jugglingdb/lib/model.js:827:33)
at ModelConstructor.next (/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/jugglingdb/lib/hooks.js:48:18)
at ModelConstructor. (/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/jugglingdb/lib/model.js:826:38)
at ModelConstructor.next (/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/jugglingdb/lib/hooks.js:48:18)
at /Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/jugglingdb/lib/model.js:825:30
at /Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/jugglingdb-mongodb/lib/mongodb.js:249:9
at /Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/jugglingdb-mongodb/node_modules/mongodb/lib/mongodb/collection.js:703:14
at null. (/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/jugglingdb-mongodb/node_modules/mongodb/lib/mongodb/db.js:1709:18)
at g (events.js:175:14)
at EventEmitter.emit (events.js:106:17)
at Server.Base._callHandler (/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/jugglingdb-mongodb/node_modules/mongodb/lib/mongodb/connection/base.js:130:25)
at /Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/jugglingdb-mongodb/node_modules/mongodb/lib/mongodb/connection/server.js:464:24
at MongoReply.parseBody (/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/jugglingdb-mongodb/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:132:5)
at null. (/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/jugglingdb-mongodb/node_modules/mongodb/lib/mongodb/connection/server.js:410:22)
at EventEmitter.emit (events.js:95:17)
at null. (/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/jugglingdb-mongodb/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:190:13)
at EventEmitter.emit (events.js:98:17)
at Socket. (/Users/camilo/Documents/Pruebas/Nodejs/interno2/node_modules/jugglingdb-mongodb/node_modules/mongodb/lib/mongodb/connection/connection.js:382:22)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket. (_stream_readable.js:699:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:382:10)
at emitReadable (_stream_readable.js:377:5)
at readableAddChunk (_stream_readable.js:142:7)
at Socket.Readable.push (_stream_readable.js:112:10)
at TCP.onread (net.js:511:21)
Versions:
nodejs: 0.10.1
compoundjs: 1.1.5-21
jubblingdb: 0.2.0-27
jugglingdb-mongodb: 0.0.4-1
The problem was a bug on jubblingdb 0.2.0-27. The author updated it to 0.2.0-28 and the problem was solved.

Resources