Skip to content

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

@abartolo

Description

@abartolo

What you are doing?

Creating a record with the same value in a column that is Unique:true. I'm using FeathersJS with uses Sequelize. 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.

Output, either JSON or SQL

image

Dialect: mysql
Database version: 5.7.13
Sequelize version: 3.24.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    staletype: bugDEPRECATED: replace with the "bug" issue type

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions