Tag: error handling

Heroku日志 – 打开错误消息中提到的日志

我正在将一个node.js应用程序部署到heroku(雪松堆栈) 我已经设置了这样的NODE_ENV: herokuconfiguration:添加NODE_ENV =生产 然后我做: git push heroku 但是,启动后(我有一个console.log生成第一个日志条目)应用程序崩溃。 我运行: heroku日志 并得到下面的错误。 我如何打开它所指的/app/log/production.log? app[web.1]: listening on port 32168 within production environment app[web.1]: app[web.1]: events.js:48 app[web.1]: throw arguments[1]; // Unhandled 'error' event app[web.1]: ^ app[web.1]: Error: ENOENT, open '/app/log/production.log' heroku[web.1]: Process exited with status 1 heroku[web.1]: State changed from starting to crashed

Node.JS:客户端请求被中断后postdata会发生什么?

在HTTP (v0.8.20) 的Node.JS文档中 ,在ServerRequest下,我看到data和end事件。 我没有看到error的事件。 通常,如果在接收数据时发生中断,我可以通过查看error来检测。 但是,这将工作postdata? 我怎样才能确定是否收到整个postdata,并且不会因为networking故障而被截断?

无法在节点js上使用摩卡运行PhantomJS

我试图用这些参数运行phantomjs: mocha-phantomjs -s disk-cache=no –ignore-leaks -R xunit tests/index.html 但总是得到这个回应: events.js:72 throw er; // Unhandled 'error' event ^ Error: spawn ENOENT at errnoException (child_process.js:980:11) at Process.ChildProcess._handle.onexit (child_process.js:771:34) 我使用的是Ubuntu 13,mocha-phantomjs 3.1.0和v0.10.15。 任何谷歌search没有帮助,我只是不知道该怎么办。 所有我以前做的,只是安装节点和mocha-phantomjs 谁能帮我?

在node.js中发送HTTP响应

我正在尝试在节点中发送一个http响应,以在浏览器中打印结果。 简化的源代码如下。 基本上,所有的variables都是在程序的某个地方定义的,所以这不应该成为问题。 当我尝试运行脚本时,我不断收到错误: http.js:783 throw new TypeError('first argument must be a string or Buffer'); TypeError: first argument must be a string or Buffer 那么熟悉node.js或javascript语法的人可以让我知道问题是什么? upload = function(req, res) { var fileInfos = [obj, obj]; //defined as an array of objects var counter = 0; counter -= 1; if (!counter) { res.end({files: fileInfos}); //files is […]

Q承诺传播错误和例外

我正在使用这个代码,以便将一个经典的nodejs函数转换为一个promise: Object.defineProperty(Function.prototype, "toPromise", { enumerable: false, configurable: false, writable: false, value: function(self) { var $this; $this = this; return function() { var arg, args, deferred, _i, _len; deferred = Q.defer(); args = []; for (_i = 0, _len = arguments.length; _i < _len; _i++) { arg = arguments[_i]; args.push(arg); } args.push(function() { args = Array.prototype.slice.call(arguments); […]

我可以指定如何处理asynchronousJavaScript库中的错误?

我正在尝试清理asynchronous函数的input。 具体来说,给定一个API的凭证列表,我试图通过向API发送一个testing请求并检查每一个的结果来筛选哪些是无效的。 我面临的问题是这样的:我想收集无效的关键到一个单一的列表。 我通常会使用async库来使用series函数按顺序执行请求。 但是,从文档: 如果系列中的任何函数将错误传递给其callback函数,则不会运行更多函数,并立即使用错误值调用callback函数。 这不是所需的行为:我想收集错误代替响应(或两者)。 这是可能的,使用这个库,而不改变我与API交互的方式?

asynchronousnode.js代码(使用Q)不写入标准错误

在编写asynchronousnode.js代码时,我遇到了以下问题: 在asynchronous块内抛出的错误不会将任何内容打印到控制台标准错误 ,它们只是失败而已。 下面是一个自包含的工作示例来重新创build问题,我在asynchronouscallback的外部和外部调用一个不存在的函数: 注意//表示的行! 注释 var Q = require('Q'); function asyncFunc(){ var deferred = Q.defer(); setTimeout(function(){ console.log('resolving promise!'); deferred.resolve('resolveMessage'); },2000); return deferred.promise; } asyncFunc() .then(function (msg) { nonExisting(); // ! calling here puts no error on the console console.log('Promise.then entered, msg:',msg); }); //nonExisting(); // ! calling here results in referenceError correctly printed to the […]

处理SailsJS中的服务器错误

我正在SailsJS中创build一个应用程序。 我遇到类似错误,types错误或500错误时发生数据库相关查询中的一些错误。我正在使用MongoDB。 有什么办法可以在服务器端捕获这个错误。 现在,这些错误正在崩溃我的服务器。 服务器停止。 我必须重新启动服务器。 请帮我解决这个问题。 提前致谢。

nodejs使用的Error构造函数的参数是什么?

我知道你可以像这样传递构造函数: err = new Error('This is an error'); 但有更多的参数,它可以处理像错误名称,错误代码等…? 我也可以像这样设置它们: err.name = 'missingField'; err.code = 99; 但为了简洁起见,如果它能接受它们,我想把它们传递给构造函数。 我可以包装的function,但只是想要做到这一点,如果需要的话。 代码的构造函数或文档在哪里? 我search了networking,nodejs.org网站和github,但没有find它。

当收到Error对象时,如何停止函数?

如何在发生错误时停止function。 我正在做一个http后的通话。 我已经构造了一个错误优先风格的callback函数。 如果传入一个Error对象,如何停止callback函数? 在我的使用情况下,我需要停止,无论错误types,因为我需要的数据对象的后续链callback函数。 它是否简单地return ? 我已经阅读了更高层次上的回报,希望得到确认,如果我的代码是正确的,我想实现。 我只是想确保继续callback函数不会继续,因为他们不会传递任何数据对象,因此,都将是'错误' server.js var request = function(callback) { // HTTP call to server }, function (error, response, body) { if (!error && response.statusCode === 200) { // processed and created data object return callback(null, data) } else { console.log(error.stack) return callback(error) ; } }) }; var requestSync = […]