QQBot.prototype.die = function (message, info) { this.dispatcher.stop_plugin(); this.started = false; if (message) { log.error("QQBot will die! message: " + message); } if (message) { console.log("QQBot will die! message: " + message); } if (info) { log.error("QQBot will die! info " + (JSON.stringify(info))); } if (info) { console.log("QQBot will die! info " + (JSON.stringify(info))); } if (this.cb_die) { return this.cb_die(); } else { return process.exit(1); } };
return function (ret, e) { //console.log(ret,e);process.exit(-1); if (e) { log.error(e); } if (ret.retcode === 0) { _this.dgroup_info = ret.result; } if (callback) { return callback(ret.retcode === 0, e || 'retcode isnot 0'); } };
exports.count = function(req, res) { try { var model = getModelForName(req.params.collection); if (model === null) { res.send(404, req.params.collection+ ' is unknown'); } else { var qry = model.count(); qry.exec(function(err, doc) { if (err !== null) res.send(500, err); else { res.set({'Content-Type': 'text/plain', 'Cache-Control' : 'no-cache,no-store,must-revalidate'}); res.send(200, JSON.stringify(doc)); } }); } } catch (ex) { if (req.params && req.params.collection) log.error('mongodbview - /api/db/count/%s Error: %s', req.params.collection, ex); else log.error('mongodbview - /api/db/count (req.params.collection unknown) Error: %s ', ex); res.send(500, ex.toString()); } }
server.on('error', function(error) { var message = 'Could not start server on port ' + port + ': ' + error; if (error.code == 'EADDRINUSE') { message = 'Port ' + PORT + ' in use, please free it and retry again'; } if (callback) { return callback(message); } log.error(message); });
/** * Handles the updateuser message. We use this to know our own nickname and * avoid challenging ourselves (like a noob would) * * @param {String} nick Our assigned nickname. * @param {Integer} status Unused. */ onUpdateUser([nick, status]) { // eslint-disable-line switch (status) { case '0': break; case '1': Log.warn(`Successfully logged in as ${nick} (${util.toId(nick)})`); mynick = util.toId(nick); break; default: Log.error(`Weird status when trying to log in: ${status} ${nick}`); break; } }
function success(documentHistoryContent) { try { var deserialisedContent = JSON.parse(documentHistoryContent); log.debug(' ---> 200 RESPONSE to get history content ' + '\n'); res.json(200, deserialisedContent); } catch(error){ log.error('error parsing document history content', error); res.send(500); } },
exports.loadTest = function(options, callback) { var constructor; if (!options.url) { log.error('Missing URL in options'); return; } for( var i = 0, l = options.url.length; i < l; i++ ) { if (!options.url[i].startsWith('http:') && !options.url[i].startsWith('https:')) { log.error('Invalid URL %s, must be http://, https:// or ws://', options.url[i]); return; } } constructor = HttpClient; options.concurrency = options.concurrency || 1; if (options.requestsPerSecond) { options.requestsPerSecond = options.requestsPerSecond / options.concurrency; } if (options.debug) { log.level = Log.DEBUG; } if (callback && !('quiet' in options)) { options.quiet = true; } var operation = new Operation(options, constructor, callback); operation.start(); return operation; };
setActive : function(index) { var trigger=this.get("trigger"); if(!trigger){ trigger="mouseenter"; } if(index==undefined && isNaN(index)){ index = 0; }; if($(".tab_labels a").eq(index).length==0){ Log.error("超出标签数量"); index =0; } $(".tab_labels a").eq(index).trigger(trigger); },
// Public: Load scripts from packages specified in the // `external-scripts.json` file. // // packages - An Array of packages containing hubot scripts to load. // // Returns nothing. loadExternalScripts (packages) { this.logger.debug('Loading external-scripts from npm packages') try { if (Array.isArray(packages)) { return packages.forEach(pkg => require(pkg)(this)) } Object.keys(packages).forEach(key => require(key)(this, packages[key])) } catch (error) { this.logger.error(`Error loading scripts from npm package - ${error.stack}`) process.exit(1) } }
Schema.find(function (err, schemas) { if(err){ log.error('Google drive init error schemas', err); return; } log.debug('Google drive init : found schemas'); for(i = 0; i < schemas.length; i++){ var currentSchema = schemas[i]; cacheGoogleDoc('init fetch schema -> ' + currentSchema.name, currentSchema.googleDocSchemaId, currentSchema._id); } });
exports.updatePreviewContent = function(req, res){ log.debug('Updating preview content'); if(req.params && req.params.id) { Document.findById(req.params.id, function (err, document) { if (err) { handleError(res, err); } else if (!document) { res.send(404); } else{ //let our sockets know that we are updating preview content preview.updatingPreviewContentEvent(req.params.id, 'preview'); var googleContentUpdateDeferred = googledrive.updateDocument(req, req.params.id, document.previewContentGoogleDocId, req.body, 'preview'); googleContentUpdateDeferred.then( function success(){ log.debug('succesfully updated google preview document'); res.send(200); }, function error(statusCode){ preview.updatingPreviewContentErrorEvent(req.params.id, 'preview'); if(typeof statusCode !== "number"){ statusCode = 500; } log.error('Failed to update google doc content', statusCode); res.send(statusCode); }); } }); } else { log.error('invalid params to update preview content'); res.send(400); } };
self.end = function(requestId, errorCode) { if (!(requestId in requests)) { log.error('Message id ' + requestId + ' not found'); return; } if (!running) { return; } add(getElapsed(requests[requestId]), errorCode); delete requests[requestId]; };
shouldError() { if (!this.options.percent) { if (this.options.error) { return true; } return false; } const percent = parseInt(this.options.percent, 10); if (!percent) { log.error('Invalid error percent %s', this.options.percent); return false; } return (Math.random() < percent / 100); }
self.interpret = function(command, options) { var commandFunction = cache[command]; if (!commandFunction) { log.error('Command %s not in cache', command); return 'ERROR'; } var syntax = syntaxes.getSyntax(command); if (!syntax) { log.error('Invalid command %s', command); return 'ERROR'; } var args = []; var order = syntax.order || syntax.protocol; for (var key in order) { args.push(options[key]); } var result = commandFunction.apply(cache, args); log.debug('Result for %s: %s', command, result); var mapped = syntax.output[result]; if (!mapped) { log.debug('Not mapped %s for %s', command, result); commandFunction = self[syntaxes.remap(command) + 'Reader']; if (!commandFunction) { log.error('Could not find reader for %s with %s', command, result); return 'ERROR'; } return commandFunction.call(self, options, result); } log.debug('Mapped %s for %s: %s', command, result, mapped); return mapped; };
/** * Run one function in the given series, go to the next. */ function runOne(callback) { if (isEmpty(series)) { return callback(null, self.result); } for (var key in series) { var value = series[key]; if (!value) { return callback('Empty test for ' + key); } else if (typeof value == 'object') { var runner = new Runner(key, value); return runner.runAll(function(error) { if (error) { log.error('Could not run all functions'); return; } self.result.add(runner.result); deleteAndRunNext(key, callback); }); } else if (typeof value == 'function') { var testKey = key; if (isNumber(key) && value.name) { testKey = value.name; } var subResult = new TestResult(testKey); // it is a function to run next = getNext(key, subResult, callback); return value(next); } else { log.error('Key %s has an invalid value %s', key, value); return deleteAndRunNext(key, callback); } // only the first element in the series is used; // the rest are called by recursion in deleteAndRunNext() return; } }
fs.readFile(path, {encoding: encoding}, function (err, data) { if (err) { logger.info("500 Internal Server Error"); logger.error("find the " + path + ". but could not read."); res.status(500).sendfile(file500); return; } var html = md(data); res.send(html); fs.writeFile(html_path, html, function (err) { if (err) { logger.warning("could not write cache to " + html_path); } }); });
Document.findById(docId, function (err, document) { if (err) { log.error('failed to find document to unlock', err); deferred.reject(); } else if(!document) { log.error('failed to find document to unlock'); deferred.reject(); } else{ document.lockedKey = undefined; document.lockedBy = undefined; document.save(function (err) { if (err) { log.error('failed to update document ', err); deferred.reject(); } else{ deferred.resolve(); } }); } });
function success(documentHistory) { try { if (typeof documentHistory === 'string') { documentHistory = JSON.parse(documentHistory); } res.json(200, documentHistory); } catch(error){ log.error('error parsing document history'); res.send(500); } },
tasksClient.myTasks({ externalId: externalId(message), perPage: 5 }, function(err, results) { if (err) { logger.error(err); return; } user.nextPage = null; results.links.forEach(function(link) { if (link.rel == 'next') { user.nextPage = url.parse(link.href, true).query.page; } }); replyFormatted(channel, formatTaskList(results) + (user.nextPage ? "\n\nType 'more' to see older tasks" : '\n\n')); });
module.exports.BaseClient.prototype.init = function() { function identity(arg) { return function() { return arg; }; } this.options = urlLib.parse(this.params.url); this.options.headers = {}; if (this.params.headers) { this.options.headers = this.params.headers; } if (this.params.cert && this.params.key) { this.options.cert = this.params.cert; this.options.key = this.params.key; } this.options.agent = false; if (this.params.body) { if (typeof this.params.body == 'string') { log.debug('Received string body'); this.generateMessage = identity(this.params.body); } else if (typeof this.params.body == 'object') { log.debug('Received JSON body'); this.generateMessage = identity(this.params.body); } else if (typeof this.params.body == 'function') { log.debug('Received function body'); this.generateMessage = this.params.body; } else { log.error('Unrecognized body: %s', typeof params.body); } this.options.headers['Content-Type'] = this.params.contentType || 'text/plain'; } headers.addUserAgent(this.options.headers); if (this.params.secureProtocol) { this.options.secureProtocol = this.params.secureProtocol; } log.debug('Options: %j',this.options); }
characteristic.read(function(error, data) { if (data) { log.debug("There is data. We don't check if it is correct yet (should be 08 01)."); var string = data.toString('ascii'); var buf = new Uint8Array(20); for (var i=0; i<string.length; i++) { buf[i] = string.charCodeAt(i); } var msg = decrypt(buf); print(msg); log.info("Turn on RGB"); callback(); } else { log.error("There is no data"); } });
storage.getItems(source, function(err, items) { if (err) { log.error('error getting current items for source %s: %s', source.url, err); callback(err); } else { allItems = sourceUtil.getUniqueItems(items, feedItems); storage.storeItems(source, allItems, function(err) { if (err) { log.error('error storing items for source %s', source.url); } callback(err); }); } });
storage.storeSource(source, function(err) { if (err) { log.error('error in storing source %s', source.url); callback(err); } else { // Store new items. addNewItems(source, feedItems, function(err) { if (err) { log.error('error in adding new items for source %s', source.url); } callback(err); }); } });
AccessTokenModel.remove({userId: req.user._id}, function (err) { if (err) { log.error(err) res.sendStatus(500) return } RefreshTokenModel.remove({userId: req.user._id}, function (err) { if (err) { log.error(err) res.sendStatus(500) return } res.sendStatus(200) }) })
auth.login_token(function (ret, client_id, ptwebqq) { if (ret.retcode === 0) { log.info('[LOGIN] success: ', account); front.initBot(); callback(all_cookies, { psessionid: ret.result.psessionid, clientid: client_id, ptwebqq: ptwebqq, uin: ret.result.uin, vfwebqq: ret.result.vfwebqq }); } else { log.info("[LOGIN] Login failed :/"); log.error(ret); process.exit(3); } });
openPendingCollection(function(error, collection) { if (error) { log.error('Could not open collection: %s', error); return callback('database not available'); } collection.find().toArray(function(error, result) { if (error) { log.error('Could not list packages: %s', error); return callback('database not available'); } return callback(null, result); }); });
openPendingCollection(function(error, collection) { if (error) { log.error('Could not open collection: %s', error); return callback('database not available'); } collection.findOne({name: name}, function(error, result) { if (error) { log.error('Could not read package %s: %s', name, error); return callback('database not available'); } return callback(null, result); }); });
openPendingCollection(function(error, collection) { if (error) { log.error('Could not open pending collection: %s', error); return callback('database not available'); } collection.update({name: object.name}, {'$set': object}, {upsert: true, w: 1}, function(error, result) { if (error) { log.error('Could not update pending package %s: %s', object.name, error); return callback('database not available'); } return callback(null, result); }); });
/** * Public: Load scripts from packages specified in the * `external-scripts.json` file. * * @param {string[]} packages - An Array of packages containing hubot scripts to load. * * Returns nothing. */ loadExternalScripts(packages) { this.logger.debug('Loading external-scripts from npm packages'); try { if (packages instanceof Array) { for (let pkg of packages) { require(pkg)(this); } } else { for (let pkg of packages) { require(pkg)(this, packages[pkg]); } } } catch(error) { this.logger.error( `Error loading scripts from npm package - ${error.stack}`); process.exit(1); } }
function shouldError() { if (!options.percent) { if (options.error) { return true; } return false; } var percent = parseInt(options.percent, 10); if (!percent) { log.error('Invalid error percent %s', options.percent); return false; } return (Math.random() < percent / 100); }