Created
April 12, 2010 21:42
-
-
Save horatio-sans-serif/364026 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/projects/node-red(master) ⚡ ack throw | |
bin/nodered | |
64- redisClients[0].hset('nr:nodes:' + NODE_NAME, 'version', NODERED_VERSION, | |
65: throwOnRedisError); | |
66- | |
-- | |
68- redisClients[0].hset('nr:nodes:' + NODE_NAME, 'upSince', now, | |
69: throwOnRedisError); | |
70- | |
71- redisClients[0].hset('nr:nodes:' + NODE_NAME, 'clientCount', '0', | |
72: throwOnRedisError); | |
73- }); | |
lib/controller.js | |
25- if (typeof transportModule.create != "function") | |
26: throw new Error("invalid transport: " + transport.name); | |
27- | |
-- | |
29- if (!(instance instanceof Object)) | |
30: throw new Error("invalid transport: " + transport.name); | |
31- | |
-- | |
33- transportModule.metadata.name != transport.name) | |
34: throw new Error("invalid transport metadata for: " + transport.name); | |
35- | |
-- | |
47- transport.ip + ":" + transport.port, | |
48: throwOnRedisError); | |
49- } | |
-- | |
65- if (this.totalClientCount() > this.config.maxClients) | |
66: throw new ProtocolError(E_CAPACITY, "server full", true); | |
67- | |
68- this.transports[transport.metadata.name].clientCount++; | |
69: this.redisClient.hincrby('nr:nodes:' + NODE_NAME, 'clientCount', 1, throwOnRedisError); | |
70- | |
-- | |
90- context.beingProcessed = false; | |
91: this.redisClient.hincrby('nr:nodes:' + NODE_NAME, 'clientCount', -1, throwOnRedisError); | |
92-}; | |
-- | |
107- if (context.input.length > this.config.maxRequestLength) | |
108: throw new ProtocolError(E_TOO_LARGE, "req too large", true); | |
109- | |
-- | |
116- if (++context.pendingRequests > this.config.maxPendingRequestsPerClient) | |
117: throw new ProtocolError(E_FLOODING, "flooding", true); | |
118- | |
-- | |
142- } catch (e) { | |
143: throw new ProtocolError(E_MALFORMED, "invalid request", true); | |
144- } | |
-- | |
150- typeof req[1] != "string") | |
151: throw new ProtocolError(E_MALFORMED, "invalid request", true); | |
152- | |
-- | |
251- function (err, reply) { | |
252: if (err) throw err; | |
253- if (reply == 1) { | |
-- | |
280- function (err, reply) { | |
281: if (err) throw err; | |
282- delete this.subscribers[chan][nick]; | |
-- | |
330- this.redisClient.publish(chan, json, function (err, count) { | |
331: if (err) throw err; | |
332- sys.debug("[CONTROLLER] message was published to " + count + " subscriber(s)"); | |
-- | |
342- function (chan) { | |
343: self.unsubscribeClient(chan, context, throwOnRedisError); | |
344- }); | |
lib/dispatcher.js | |
15- if (typeof api != "object") | |
16: throw new Error("Invalid request extension: " + moduleName + " API is not an object"); | |
17- | |
18- if (commandNames.length == 0) | |
19: throw new Error("Invalid request extension API; no commands: " + moduleName); | |
20- | |
-- | |
25- if (typeof callback != "function") | |
26: throw new Error("callback function required"); | |
27- | |
-- | |
33- if (self.handlers.hasOwnProperty(fullCommandName)) | |
34: throw new Error(fullCommandName + " is already registered."); | |
35- self.handlers[fullCommandName] = callback; | |
-- | |
50- if (!this.handlers.hasOwnProperty(commandName)) | |
51: throw new ProtocolError(E_UNKNOWN_COMMAND, commandName, true); | |
52- | |
53- if (typeof this.handlers[commandName] != "function") | |
54: throw new ProtocolError(E_INTERNAL, commandName, true); | |
55- | |
lib/redis.js | |
11-// programming errors and should be caught during development, so we provide | |
12:// this function which throws. It's only useful in cases where the caller does | |
13-// not care about the reply ("fire and forget [unless I fired the wrong way]"). | |
14- | |
15:global.throwOnRedisError = function (err, reply) { | |
16: if (err) throw err; | |
17-}; | |
-- | |
38- if (isNaN(cfg.dbNo) || cfg.dbNo < 0) | |
39: throw new Error("invalid --redis-db=<number>"); | |
40- } | |
-- | |
63- function () { | |
64: clients[0].select(redisConfig.dbNo, throwOnRedisError); | |
65- | |
-- | |
67- function (err, added) { | |
68: if (err) throw err; | |
69- | |
70- if (!added) | |
71: throw new Error("non-unique node name: '" + NODE_NAME + "'"); | |
72- }); | |
-- | |
76- function () { | |
77: clients[1].select(redisConfig.dbNo, throwOnRedisError); | |
78- | |
-- | |
80- function (err, value) { | |
81: if (err) throw err; | |
82- | |
lib/requests/builtin.js | |
43- function (err, nodeNames) { | |
44: if (err) throw err; | |
45- redis.convertMultiBulkBuffersToUTF8Strings(nodeNames); | |
-- | |
50- function (err, nodeInfo) { | |
51: if (err) throw err; | |
52- redis.convertMultiBulkBuffersToUTF8Strings(nodeInfo); | |
-- | |
65- if (newNick.length == 0) | |
66: throw new ProtocolError(E_ARGS, "nick required"); | |
67- | |
68- if (newNick === oldNick) | |
69: throw new ProtocolError(E_ARGS, "same nick as current"); | |
70- | |
-- | |
73- function (err, added) { | |
74: if (err) throw err; | |
75- if (!added) { | |
-- | |
78- context.nickname = newNick; | |
79: redisClient.srem("nr:nicks", oldNick, throwOnRedisError); | |
80- var controller = context.controller; | |
-- | |
88- function (err, reply) { | |
89: if (err) throw err; | |
90- redisClient.sadd('nr:ch:' + chan, newNick, | |
91- function (err, reply) { | |
92: if (err) throw err; | |
93- controller.changeNickIn(chan, context, oldNick, newNick); | |
-- | |
99- function (err, count) { | |
100: if (err) throw err; | |
101- sys.debug("[BUILTIN] nickchange sent to " + count); | |
-- | |
125- function (err, reply) { | |
126: if (err) throw err; | |
127- redis.convertMultiBulkBuffersToUTF8Strings(reply); | |
-- | |
136- if (chan.length == 0) | |
137: throw new ProtocolError(E_ARGS, "channel required"); | |
138- | |
-- | |
140- function (err, memberCount) { | |
141: if (err) throw err; | |
142- reply.reply(req, context, memberCount); | |
-- | |
150- if (chan.length == 0) | |
151: throw new ProtocolError(E_ARGS, "channel required"); | |
152- | |
153- if (messageBody.length == 0) | |
154: throw new ProtocolError(E_ARGS, "message required"); | |
155- | |
-- | |
163- function (err, reply) { | |
164: if (err) throw err; | |
165- sys.debug("[BUILTIN] published to " + reply + " subscribers."); | |
-- | |
172- context.controller.config.maxAllowedSubscriptions) | |
173: throw new ProtocolError(E_LIMIT, "too many subscriptions"); | |
174- | |
-- | |
177- if (chan.length == 0) | |
178: throw new ProtocolError(E_ARGS, "channel required"); | |
179- | |
180- if (typeof context.subscriptions[chan] != "undefined") | |
181: throw new ProtocolError(E_ARGS, "already subscribed"); | |
182- | |
-- | |
194- if (chan.length == 0) | |
195: throw new ProtocolError(E_ARGS, "channel required"); | |
196- | |
lib/transports/tcp/client.js | |
31- if (!(obj instanceof Array)) | |
32: throw new Error("Not an array"); | |
33- if (obj.length < 2) | |
34: throw new Error("Not at least length 2"); | |
35- | |
-- | |
48- } else { | |
49: throw new Error("Received reply but no one cares"); | |
50- } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sys = require("sys"); | |
global.ProtocolError = function (code, msg, fatal) { | |
Error.call(this, msg); | |
this.code = code; | |
this.fatal = fatal; | |
}; | |
sys.inherits(ProtocolError, Error); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment