Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property '2' of null #71

Closed
abartolo opened this issue Oct 19, 2016 · 7 comments
Closed

TypeError: Cannot read property '2' of null #71

abartolo opened this issue Oct 19, 2016 · 7 comments

Comments

@abartolo
Copy link

Hello,

So I'm giving FeathersJs a try and so far its supper easy to create quick rest apis. However I am stuck on an issue when creating a duplicate record where the table column is unique. I came across this issue when testing since other application might want to send a POST request to create a record but it "email" for example might already be used.

What you are doing?

Creating a record with the same value in a column that is Unique:true. I successfully inserted new record via restful api using Postman. However if I send the same request again( create a user with the same email which the column is unique) it crashes the server with error "TypeError: Cannot read property '2' of null".

Below is the model I am using

// code here
const Sequelize = require('sequelize');

module.exports = function(sequelize) {
  const user = sequelize.define('users', {
    email: {
      type: Sequelize.STRING,
      allowNull: false,
      unique: true
    },
    password: {
      type: Sequelize.STRING,
      allowNull: false
    }
  }, {
    freezeTableName: true
  });

What do you expect to happen?

I expected to get a response back with an error stating its a duplicate or at least a clean error.

What is actually happening?

Crashed server since error wasn't caught.

Error Image

image

Dialect: mysql
Database version: 5.7.13
Sequelize version: 3.24.4

@abartolo
Copy link
Author

Update - Issue above was @ work. I tried to replicate @ home and got the following response. I will download dependencies @work again in case there was an issue I missed something.

Dialect: mysql
Database version: 5.6.25
Sequelize version: 3.24.4

{ "name": "BadRequest", "message": "Validation error", "code": 400, "className": "bad-request", "errors": [ { "message": "test_description_UNIQUE must be unique", "type": "unique violation", "path": "test_description_UNIQUE", "value": "netace_edgeUpdate_creditCard_splitpayment_visa" } ] }

@daffl
Copy link
Member

daffl commented Oct 20, 2016

Thank you for the detailed report. That last response looks more like what it should do. I'd say a dependency issue or a problem with the database.

@abartolo
Copy link
Author

abartolo commented Oct 20, 2016

@daffl After reinstalling dependencies and seeing no issue - the same issue occurred :(. Sucks im really enjoying Feathers at home. super easy.

So after more analysis I found the node version i'm using is v4.2.1 @ work. This is a red flag since FeatherJS documentation is stating node 5+ and if anything is below is required to use babel.

This is the NPM Error I get below the first image I attached.
image

Not sure if this is related to this issue but I will work on updating my node and see if that fixes the issue.

@daffl what are the chances this is a due to babel not executing properly.. I have a feeling because @ work security is very strict.. I can't even update node without following a process..

@daffl
Copy link
Member

daffl commented Oct 20, 2016

That does look like a Babel error. It should work with Node v4 but with strict security restrictions it makes sense something during installation went wrong.

I recommend using nvm to install the latest version and try that. You might want to re-initialize the application so that it doesn't enable Babel (this is only done for Node < 5).

@abartolo
Copy link
Author

@daffl It seems to be mysql version issue. I originally opened issue at sequelize repository but was initially closed assuming it wasn't a sequelize issue but then recently reopened. Luckily the mysql version locally installed at work is version 5.6.15 didn't display this issue VS. the mysql 5.7.13 where I got this issue.

I replicated both table structures and unique indexes as seen below. Sent a POST to create a new record and immediately sent the POST again to recreate the crash but this time the server did not crash and instead got a JSON error as expected.

Expected Response with mysql version 5.6.15
{ "test_description": "b2b_edgeFlow_creditCard_visa_splitpayment_3", "status": "failed", "build_date": "2016-08-01 15:20:28" }

Both have the same Table and Indexes
image

Indexes
image

@daffl
Copy link
Member

daffl commented Oct 20, 2016

Glad it is working. Can we close since it seems to be a Sequelize/MySQL issue?

@marshallswain
Copy link
Member

I'm going to close this, for now. @abartolo please reopen if you feel like there's something that can be done on our end. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants