jovotech / jovo-framework

🔈 The React for Voice and Chat: Build Apps for Alexa, Messenger, Instagram, the Web, and more
https://www.jovo.tech
Apache License 2.0
1.68k stars 309 forks source link

Cannot read property 'userData' of null - Problem when using an existing DynamoDB Table #187

Closed superjose closed 6 years ago

superjose commented 6 years ago

I'm submitting a...

First of all. Thank you, thank you thank you so much for all the great and hard work you've put into this! It's fantastic. Even if you target Alexa only devices it's an enjoyment to prototype so fast!! The source code is also easy to follow 👍

Kudos for the team!

I just wanted to give a heads up to make a clarification in the documentation not to use an existing DynamoDB table that wasn't created by Jovo. You will run into "Cannot read property 'userData' of null". Jovo sets up its own userId as the main Primary Key (Partition), and if you set something that doesn't match it, it will throw an error.

I went for 3 hours, without knowing the issue, I wasn't able to connect Jovo to the DynamoDB AWS database. I thought permissions were at fault, and I checked them over and over again.

I can help out by creating a PR by making a notice in the documentation... or maybe helping to modify : lib/integrations/db/dynamoDb.js Line 163 - Line 193.

Expected Behavior

Let the user know that the table has been setup incorrectly or that it's incompatible on how Jovo handles it.

Current Behavior

It gives the error

Error log

Cannot read property 'userData' of null
    at platform.jovo.db.loadObject (D:\AllData\Dropbox\Personal Brand\Alexa Skill - Web Developer\node_modules\jovo-framework\lib\user.js:39:33)
    at DynamoDb.checkResourceNotFound (D:\AllData\Dropbox\Personal Brand\Alexa Skill - Web Developer\node_modules\jovo-framework\lib\integrations\db\dynamoDb.js:330:13)
    at Response.<anonymous> (D:\AllData\Dropbox\Personal Brand\Alexa Skill - Web Developer\node_modules\jovo-framework\lib\integrations\db\dynamoDb.js:211:22)
    at Request.<anonymous> (D:\AllData\Dropbox\Personal Brand\Alexa Skill - Web Developer\node_modules\aws-sdk\lib\request.js:364:18)
    at Request.callListeners (D:\AllData\Dropbox\Personal Brand\Alexa Skill - Web Developer\node_modules\aws-sdk\lib\sequential_executor.js:105:20)
    at Request.emit (D:\AllData\Dropbox\Personal Brand\Alexa Skill - Web Developer\node_modules\aws-sdk\lib\sequential_executor.js:77:10)
    at Request.emit (D:\AllData\Dropbox\Personal Brand\Alexa Skill - Web Developer\node_modules\aws-sdk\lib\request.js:683:14)
    at Request.transition (D:\AllData\Dropbox\Personal Brand\Alexa Skill - Web Developer\node_modules\aws-sdk\lib\request.js:22:10)
    at AcceptorStateMachine.runTo (D:\AllData\Dropbox\Personal Brand\Alexa Skill - Web Developer\node_modules\aws-sdk\lib\state_machine.js:14:12)
    at D:\AllData\Dropbox\Personal Brand\Alexa Skill - Web Developer\node_modules\aws-sdk\lib\state_machine.js:26:10
Timeout error: No response after 5000 milliseconds
Unhandled Rejection at: Promise Promise {
  <rejected> { Error: read ECONNRESET
    at _errnoException (util.js:999:13)
    at TCP.onread (net.js:629:25) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' } } reason: { Error: read ECONNRESET
    at _errnoException (util.js:999:13)
    at TCP.onread (net.js:629:25) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' }
Unhandled Rejection at: Promise Promise {
  <rejected> { Error: connect ECONNREFUSED 127.0.0.1:3000
    at Object._errnoException (util.js:999:13)
    at _exceptionWithHostPort (util.js:1020:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1207:14)
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 3000 } } reason: { Error: connect ECONNREFUSED 127.0.0.1:3000
    at Object._errnoException (util.js:999:13)
    at _exceptionWithHostPort (util.js:1020:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1207:14)
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 3000 }

Your Environment

jankoenig commented 6 years ago

Hi @superjose, thanks for this detailed description! Would appreciate a PR or some thoughts regarding the specific lines you're mentioning :) Thanks!

superjose commented 6 years ago

@jankoenig Oh! So sorry for taking this long! Absolutely! I'll take a look into it, and do the changes!

jankoenig commented 6 years ago

Closing this for now, added some more info regarding Lambda permissions here: https://www.jovo.tech/guides/add-dynamodb-database