Using compound, I got an error on update when using validatesPresenceOf - node.js

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.

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.

Neo4j's NPM component blows up without error

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?

NodeLoad module gives Error : Object #<Client> has no method 'destroy'

I am using NodeLoad module of nodejs for sending multiple request at same time for testing server node app, but if i use numUsers : 50 than it's work perfectly for me. When I take numUsers : 300 than Gives me Error Like : TypeError: Object #<Client> has no method 'destroy'
NodeLoad App I used
timeLimit: 10,
targetRps: 5,
numUsers : 300,
Error :
},reconnect=function(){var oldclient=client;if(oldclient){oldclient.destroy();
^
TypeError: Object #<Client> has no method 'destroy'
at reconnect (/root/nodeLoadDemo/nodeload/node_modules/nodeload/nodeload.js:9:506)
at Client.<anonymous> (/root/nodeLoadDemo/nodeload/node_modules/nodeload/nodeload.js:10:180)
at Client.EventEmitter.emit (events.js:117:20)
at ClientRequest.<anonymous> (http.js:2144:10)
at ClientRequest.EventEmitter.emit (events.js:95:17)
at Socket.socketOnEnd [as onend] (http.js:1568:9)
at Socket.g (events.js:180:16)
at Socket.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:919:16
at process._tickCallback (node.js:419:13)
So, can any one Explain me How Error ? And Solution for these Error ?
Thank you .
I got an Answer
Click Here To go on Solution
You Just need to change in node modules. open nodeload modules and nodeload.js file check line 9 at end of sentence replace
if (oldclient) { oldclient.destroy(); }
TO
if (oldclient && oldclient.destroy) { oldclient.destroy(); }

rs/pushd crashes when a new subscriber is received

I'm trying to use https://github.com/rs/pushd as a push notification server.
Whenever I try to add a new subscriber, the server crashes with this stack trace:
/home/ec2-user/push_server/pushd/node_modules/redis/index.js:602
throw err;
^
TypeError: Cannot set property 'id' of null
at /home/ec2-user/push_server/pushd/lib/api.coffee:20:21
at /home/ec2-user/push_server/pushd/lib/subscriber.coffee:133:21
at try_callback (/home/ec2-user/push_server/pushd/node_modules/redis/index.js:592:9)
at RedisClient.return_reply (/home/ec2-user/push_server/pushd/node_modules/redis/index.js:685:13)
at HiredisReplyParser.<anonymous> (/home/ec2-user/push_server/pushd/node_modules/redis/index.js:321:14)
at HiredisReplyParser.emit (events.js:95:17)
at HiredisReplyParser.execute (/home/ec2-user/push_server/pushd/node_modules/redis/lib/parser/hiredis.js:43:18)
at RedisClient.on_data (/home/ec2-user/push_server/pushd/node_modules/redis/index.js:547:27)
at Socket.<anonymous> (/home/ec2-user/push_server/pushd/node_modules/redis/index.js:102:14)
at Socket.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:765:14)
at Socket.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:427:10)
at emitReadable (_stream_readable.js:423:5)
at readableAddChunk (_stream_readable.js:166:9)
at Socket.Readable.push (_stream_readable.js:128:10)
at TCP.onread (net.js:529:21)
This is the command that should add a new subscriber (example from the documentation), and causes the crash:
curl -d proto=apns -d token=FE66489F304DC75B8D6E8200DFF8A456E8DAEACEC428B427E9518741C92C6660 -d lang=fr -d badge=0 -d category=show -d contentAvailable=true http://localhost/subscribers
The crash happens before the subscriber is added to the database.
The server is a RHEL micro instance on AWS
Versions
Redis Server 2.8.19.
Node.js 0.10.36.
CoffeeScript 1.9.0
Any help will be appreciated.
/lib/event.coffee
- throw new Error("Missing redis connection") if not redis?
+ throw new Error("Missing redis connection") if not #redis?
/lib/subscriber.coffee
- if info?.updated? # subscriber exists
+ if #info?.updated? # subscriber exists
# transform numeric value to number type
- for own key, value of info
+ for own key, value of #info

Nodejs TypeError: Cannot read property 'chId' of undefined

I have Omegle-clone chat service. In stress my nodejs (over 150 users) crash with error "TypeError: Cannot read property 'chId' of undefined" .
/home/kotka/randomi.fi/beta/varaserver2/channel.js:67
f = this.channels[e].chId;
^
TypeError: Cannot read property 'chId' of undefined
at Channel.joinChannel (/home/kotka/randomi.fi/beta/varaserver2/channel.js:67:23)
at Session.createSession (/home/kotka/randomi.fi/beta/varaserver2/session.js:21:23)
at /home/kotka/randomi.fi/beta/varaserver2/path.js:1:268
at Server.<anonymous> (/home/kotka/randomi.fi/beta/varaserver2/fu.js:43:3)
at Server.emit (events.js:70:17)
at HTTPParser.onIncoming (http.js:1610:12)
at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:91:29)
at Socket.ondata (http.js:1506:22)
at TCP.onread (net.js:374:27)
What is problem and how I can fix it?
channel.js source
try capturing the exception with
process.on('uncaughtException', function(err) {
console.error(err.stack);
});
This just means that this.channels[e] is undefined and does not have a chId attribute.

Resources