I’m unable to create a connection with my custom SQL database. Whatever I try I get the error message: '“[Error] Cannot read property ‘0’ of undefined”
Even when I try a simple console.log(). I can’t that error.
My script:
function create(user, callback) {
//this example uses the "tedious" library
//more info here: http://pekim.github.io/tedious/index.html
const bcrypt = require('bcrypt');
const sqlserver = require('tedious@1.11.0');
const Connection = sqlserver.Connection;
const Request = sqlserver.Request;
const TYPES = sqlserver.TYPES;
const connection = new Connection({
userName: 'username',
password: 'pass',
server: 'blabla.database.windows.net',
options: {
database: 'myDB'
}
});
const query = 'INSERT INTO dbo.Users SET Email = @Email, Password = @Password';
connection.on('debug', function(text) {
console.log(text);
}).on('errorMessage', function(text) {
console.log(JSON.stringify(text, null, 2));
}).on('infoMessage', function(text) {
console.log(JSON.stringify(text, null, 2));
});
connection.on('connect', function (err) {
if (err) return callback(err);
const request = new Request(query, function (err, rows) {
if (err) return callback(err);
// console.log('rows: ' + rows);
callback(null);
});
bcrypt.hash(user.password, 10, function(err, hash) {
if (err) return callback(err);
request.addParameter('Email', TYPES.VarChar, user.email);
request.addParameter('Password', TYPES.VarChar, hash);
connection.execSql(request);
});
});
}
Can you check if you have any Hooks enabled in the Dashboard? That error typically means there is an uncaught/unhandled error in a Hook or Rule code and the output is being shown. Could you take a look at any enabled Hooks and maybe try testing with them disabled or review for where the error could be coming from. You can troubleshoot this further by using the Realtime Webtask Logs extension (Real-time Webtask Logs Extension) to see any custom or console.log() text output.
Let me know if you can take a look at the above information.
I already turned off all rules and there is no hooks, but I still get the error:
Code generated an uncaught exception: TypeError: Cannot read property '0' of undefined
at Request._callback (/data/io/node12/08d2d352-4efb-48ab-806a-d4c823e97962/webtask.js:23:26)
at Request.self.callback (/data/sandbox/node12/node_modules/auth0-authz-rules- api/node_modules/request/request.js:188:22)
at Request.emit (events.js:315:20)
at Request.EventEmitter.emit (domain.js:505:15)
at Request.<anonymous> (/data/sandbox/node12/node_modules/auth0-authz-rules- api/node_modules/request/request.js:1171:10)
at Request.emit (events.js:315:20)
at Request.EventEmitter.emit (domain.js:505:15)
at IncomingMessage.<anonymous> (/data/sandbox/node12/node_modules/auth0-authz-rules- api/node_modules/request/request.js:1091:12)
at Object.onceWrapper (events.js:421:28)
at IncomingMessage.emit (events.js:327:22)
Could you please help us understand the issue a little more providing the following information?
1- Could you tell us when you are getting that error? (Running the project, Attempting to login)
2- Could you share some screen shots of the error you are seeing?
3- Could you share the specific URL from the example you are following?
4- If the error is when you are attempting to login, could you please check the logs and see if there is any entry about this issue? Also, make a Har file and attach this file to your answer in a Direct Message.
I’m using a custom database and attempting to test the “create a new account” function. I made some slight adjustments to the function to fit my database, but it looks very similar to the original template provided:
Since the test sign-in box only prompts for an email and password (even when i turn “require username” on) i’m inserting a dummy value for the username in the meantime. I get the exact same error of “Cannot read property ‘0’ of undefined”, and the Real-Time Webtask logs extension notes that the “Script generated an unhandled asynchronous exception”. From what I understand from the log, one of my variables is null, likely because an asynchronous function did not finish and set said variable before subsequent functions attempted to use it. The problem is that I don’t know which variable this is.
Hope this helps. Let me know if you’d like the full log as well.
Hello! I wanted to send a follow-up response as a check in since it’s been about a week. This is our log response when attempting to create a new account using the node.js script template for SQLServer (specifically by using save & try). Note that we aren’t using any rules or hooks.
Code generated an uncaught exception: TypeError: Cannot read property '0' of undefined
at Request.userCallback (/data/io/node12/c7a37968-3df9-40a6-a65e-b3601bdee901/webtask.js:41:25)
at Request.callback (/data/_verquire/_node12/tedious/1.11.0/node_modules/tedious/lib/request.js:30:27)
at Connection.message (/data/_verquire/_node12/tedious/1.11.0/node_modules/tedious/lib/connection.js:283:29)
at Connection.dispatchEvent (/data/_verquire/_node12/tedious/1.11.0/node_modules/tedious/lib/connection.js:752:59)
at MessageIO.<anonymous> (/data/_verquire/_node12/tedious/1.11.0/node_modules/tedious/lib/connection.js:685:22)
at MessageIO.emit (events.js:314:20)
at MessageIO.EventEmitter.emit (domain.js:483:12)
at MessageIO.eventData (/data/_verquire/_node12/tedious/1.11.0/node_modules/tedious/lib/message-io.js:58:21)
at Socket.<anonymous> (/data/_verquire/_node12/tedious/1.11.0/node_modules/tedious/lib/message-io.js:3:59)
at Socket.emit (events.js:314:20)
Additionally, when I tried to create an account in the “test database connection” window, I receive a “400 Bad Request” error in my developer console. The deadling for the project this is for is coming up soon, so any recommendations for things to try are greatly appreciated.
I am also having the same exception “Cannot read property ‘0’ of undefined” while using Custom Database Create Action Script. I don’t have any active Hooks and Rules enabled. In my script I have deleted all the database related scripts and only have console log but still getting the same exception.
{
"code": 500,
"error": "Script generated an unhandled asynchronous exception.",
"details": "TypeError: Cannot read property '0' of undefined",
"name": "TypeError",
"message": "Cannot read property '0' of undefined",
"stack": "TypeError: Cannot read property '0' of undefined\n at Request.userCallback (/data/io/node12/c65481e1-f253-4ff0-9953-a67d6a1ac86a/webtask.js:41:25)\n at Request.callback (/data/_verquire/_node12/tedious/1.11.0/node_modules/tedious/lib/request.js:30:27)\n at Connection.message (/data/_verquire/_node12/tedious/1.11.0/node_modules/tedious/lib/connection.js:283:29)\n at Connection.dispatchEvent (/data/_verquire/_node12/tedious/1.11.0/node_modules/tedious/lib/connection.js:752:59)\n at MessageIO.<anonymous> (/data/_verquire/_node12/tedious/1.11.0/node_modules/tedious/lib/connection.js:685:22)\n at MessageIO.emit (events.js:314:20)\n at MessageIO.EventEmitter.emit (domain.js:483:12)\n at MessageIO.eventData (/data/_verquire/_node12/tedious/1.11.0/node_modules/tedious/lib/message-io.js:58:21)\n at Socket.<anonymous> (/data/_verquire/_node12/tedious/1.11.0/node_modules/tedious/lib/message-io.js:3:59)\n at Socket.emit (events.js:314:20)"
}
Code generated an uncaught exception: TypeError: Cannot read property '0' of undefined
at Request.userCallback (/data/io/node12/c65481e1-f253-4ff0-9953-a67d6a1ac86a/webtask.js:41:25)
at Request.callback (/data/_verquire/_node12/tedious/1.11.0/node_modules/tedious/lib/request.js:30:27)
at Connection.message (/data/_verquire/_node12/tedious/1.11.0/node_modules/tedious/lib/connection.js:283:29)
at Connection.dispatchEvent (/data/_verquire/_node12/tedious/1.11.0/node_modules/tedious/lib/connection.js:752:59)
at MessageIO.<anonymous> (/data/_verquire/_node12/tedious/1.11.0/node_modules/tedious/lib/connection.js:685:22)
at MessageIO.emit (events.js:314:20)
at MessageIO.EventEmitter.emit (domain.js:483:12)
at MessageIO.eventData (/data/_verquire/_node12/tedious/1.11.0/node_modules/tedious/lib/message-io.js:58:21)
at Socket.<anonymous> (/data/_verquire/_node12/tedious/1.11.0/node_modules/tedious/lib/message-io.js:3:59)
at Socket.emit (events.js:314:20)
I was able to resolve this issue.
Actually it is in the template. When Create Action is getting called, i try-create Auth0 api calls Get User Action and in the Get User Action template following should be the change
const request = new Request(query, function (err, rowCount, rows) {
if (err || rowCount < 1) return callback(err);
instead of
const request = new Request(query, function (err, rowCount, rows) {
if (err) return callback(err);