我正在尝试在文本框旁边显示错误消息,但未显示。 我怎么了 我无法解决此问题。 我更改了表格的宽度,但结果没有变化。 function chkname() { var myname = document.getElementById("names"); if (myname ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
Sails.js 1.0.2
你好 我尝试调试回调中的错误,但唯一的消息是此消息:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
WARNING: Something seems to be wrong with this function.
It is trying to signal that it has finished AGAIN, after
already resolving/rejecting once.
(silently ignoring this...)
To assist you in hunting this down, here is a stack trace:
```
at /node/zg-sails-v1/node_modules/sails-mongo/lib/private/do-with-connection.js:242:28
at /node/zg-sails-v1/node_modules/sails-mongo/lib/private/do-with-connection.js:123:18
at Object.success (/node/zg-sails-v1/node_modules/sails-mongo/lib/private/build-std-adapter-method.js:61:47)
at /node/zg-sails-v1/node_modules/machine/lib/private/help-build-machine.js:1509:30
at proceedToFinalAfterExecLC (/node/zg-sails-v1/node_modules/parley/lib/private/Deferred.js:1151:14)
at proceedToInterceptsAndChecks (/node/zg-sails-v1/node_modules/parley/lib/private/Deferred.js:909:12)
at proceedToAfterExecSpinlocks (/node/zg-sails-v1/node_modules/parley/lib/private/Deferred.js:841:10)
at /node/zg-sails-v1/node_modules/parley/lib/private/Deferred.js:303:7
at /node/zg-sails-v1/node_modules/machine/lib/private/help-build-machine.js:964:24
at Function.handlerCbs.success (/node/zg-sails-v1/node_modules/machine/lib/private/help-build-machine.js:824:26)
at findCb (/node/zg-sails-v1/node_modules/sails-mongo/lib/private/machines/find-records.js:138:20)
at handleCallback (/node/zg-sails-v1/node_modules/mongodb/lib/utils.js:120:56)
at /node/zg-sails-v1/node_modules/mongodb/lib/cursor.js:860:16
at handleCallback (/node/zg-sails-v1/node_modules/mongodb-core/lib/cursor.js:171:5)
at setCursorDeadAndNotified (/node/zg-sails-v1/node_modules/mongodb-core/lib/cursor.js:505:3)
at nextFunction (/node/zg-sails-v1/node_modules/mongodb-core/lib/cursor.js:651:7)
at Cursor.next [as _next] (/node/zg-sails-v1/node_modules/mongodb-core/lib/cursor.js:692:3)
at fetchDocs (/node/zg-sails-v1/node_modules/mongodb/lib/cursor.js:856:10)
at /node/zg-sails-v1/node_modules/mongodb/lib/cursor.js:879:7
at handleCallback (/node/zg-sails-v1/node_modules/mongodb-core/lib/cursor.js:171:5)
at nextFunction (/node/zg-sails-v1/node_modules/mongodb-core/lib/cursor.js:682:5)
at /node/zg-sails-v1/node_modules/mongodb-core/lib/cursor.js:593:7
```
我只想显示错误信息。 后面有堆栈跟踪,但对我没有帮助。
这是我的代码示例:
User.find({id: id}).exec((err, user) => {
if (err) {
...
} else {
...
console.log(myUndefinedVar);
}
});
这是一个具有数百个回调的遗留项目,因此我无法通过等待,尝试/捕获来重构所有代码。
谢谢。
编辑:添加了Stacktrace
编辑:新示例,eslint不挂出。
Game.find({id: req.session.gameID}).exec((err, objGame) => {
if (err) {
utilService.newLog('error', stackTrace, __line, 'Game.find({id: req.session.gameID: ' + req.session.gameID + ' ...');
utilService.newLog('error', stackTrace, __line, err);
return res.redirect('dashboard');
} else if (typeof objGame === 'undefined') {
utilService.newLog('error', stackTrace, __line, 'objGame === undefined ...');
utilService.newLog('error', stackTrace, __line, err);
return res.redirect('dashboard');
} else {
...
}
});
这个
Game.find({id: req.session.gameID}).exec((err, objGame) => {
objGame是一个数组
} else if (typeof objGame === 'undefined') {
...
jsfiles = sails.config.gameCfg[objGame.type].dev.jsfiles;
一定是
} else if (typeof objGame[0] === 'undefined') {
因为objGame [0]未定义
不显示错误,仅显示警告。
这些错误发生了很多次。 仅帮助一件事-将所有回调都转换为异步函数。 然后我可以看到错误。
错误:
function some_method() {
User.find().limit(1).exec(function(err, users) {
if(err) console.log(err);
console.log(users[1].id)
// i will get the error "WARNING: Something..."
// because i am querying just 1 User, and trying to log second user
});
}
好:
async function some_method() {
var users = await User.find().limit(1);
console.log(users[1].id)
// i will see the exact error , which shows exactly where is the problem
// and say, that i am trying to read property id of undefined.
// You dont even need to console the Errors - it does it automatically!
}
但是,如果您的整个项目都充满了回调,则至少可以帮助您发现问题何时出现。 由于此消息无助于根本不知道问题出在哪里。 它可以在整个项目中的任何地方。 您可以做的- 临时处理这些问题,直到从回调到异步替换所有代码为止。
1)创建测井系统。 记录每个请求。 我正在使用温斯顿。 记录每个请求,以毫秒为单位写入请求时间。 如果使用pm2,请不要将这些请求日志写入控制台,因为那样您就看不到何时发生真正的错误。
下一个:
2)覆盖此警告以写它出现的时间。 转到
node_modules/parley/lib/private/Deffered.js
,在2个地方编写了此警告。 替换为:(new Date()) + '---' + (new Date().getTime()) + '---WARNING: Something seems to be wrong with this function...
因此,现在您至少可以知道哪个请求是错误的。 如果项目几乎被放弃,这种方法会有所帮助。 但是,如果项目处于活动状态,则应将每个方法重写为异步等待状态。 我已经花了6个月的时间-将整个后端重写为async-await,它确实非常有用-代码更好,所有错误都非常清楚。
如果使用create,update或find,请使用await
。
var new game = await Game.find({id: req.session.gameID}).exec((err, objGame) => {
if (err) {
utilService.newLog('error', stackTrace, __line, 'Game.find({id: req.session.gameID: ' + req.session.gameID + ' ...');
utilService.newLog('error', stackTrace, __line, err);
return res.redirect('dashboard');
} else if (typeof objGame === 'undefined') {
utilService.newLog('error', stackTrace, __line, 'objGame === undefined ...');
utilService.newLog('error', stackTrace, __line, err);
return res.redirect('dashboard');
} else {
...
}
});
但请确保您的函数是异步函数fn: async function () {}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.