strongloop / loopback

LoopBack makes it easy to build modern applications that require complex integrations.
http://loopback.io
Other
13.23k stars 1.2k forks source link

ValidationError: The `CarDriver` instance is not valid. Details: `email` is invalid (value: "bond@gmail.com") #1803

Closed gholias closed 6 years ago

gholias commented 8 years ago

I a have a class that inherits from the Loopback user class.

I started getting an error this morning after I update to the latest version.

ValidationError: The `CarDriver` instance is not valid. Details: `email` is invalid (value: "bond@gmail.com")

Is there anything Im missing?

This is my CarDrive model definition


    {
      "name": "CarDrive",
      "base": "User",
      "idInjection": true,
      "options": {
        "validateUpsert": true
      },
      "properties": {
        "fullName": {
          "type": "string",
          "required": true
        },
        "firstName": {
          "type": "string",
          "required": true
        },
        "lastName": {
          "type": "string",
          "required": true
        },
        "email": {
          "type": "string",
          "required": true
        },
        "telephone": {
          "type": "string",
          "required": true
        },
        "realm": false,
        "driverPDF": {
          "type": "Text",
          "required": true,
            "oracle":{
                "dataType":"LONG"
            }
        },
        "UUID": {
          "type": "string",
          "required": true
        },
        "age": {
          "type": "number",
          "required": true
        },
        "status": {
          "type": "boolean",
          "required": true
        },
        "optOut": {
          "type": "boolean",
          "required": true
        }
      },
      "validations": [],
      "relations": {
        "accessTokens": {
          "type": "hasMany",
          "model": "accessToken",
          "foreignKey": "userId"
        }
      },
      "acls": [
        {
          "accessType": "EXECUTE",
          "principalType": "ROLE",
          "principalId": "$everyone",
          "permission": "ALLOW",
          "property": "create"
        },
        {
          "accessType": "EXECUTE",
          "principalType": "ROLE",
          "principalId": "$authenticated",
          "permission": "ALLOW",
          "property": "leave"
        },
          {
              "accessType": "EXECUTE",
              "principalType": "ROLE",
              "principalId": "$authenticated",
              "permission": "ALLOW",
              "property": "optout"
          }
      ],
      "methods": {}
    }

I appreciate any help

Amir-61 commented 8 years ago

Could you please provide me a sample repo to re-produce the issue? SEE: https://github.com/strongloop/loopback/wiki/Reporting-issues#bug-report

mariohmol commented 8 years ago

I'm having EXACLTY the same error. If I use a not valid email (like bondgmailcom) it says a differente message "must provide a valid email""

If i use the base class , User, it works like a charm

{
  "name": "AccountUser",
  "base": "User",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "mysql": {
    "schema": "prod",
    "table": "account_user"
  },
  "properties": {},
  "validations": [],
  "relations": {},
  "acls": [
    {
      "accessType": "READ",
      "principalType": "ROLE",
      "principalId": "$everyone",
      "permission": "ALLOW"
    }
  ],
  "methods": {}
}
module.exports = function(AccountUser) {
};
AccountUser
            .create({
             email: emailregistro.value,
             password: senharegistro.value
           })
           .$promise.then(function(resp) {
                console.log(resp);
                alert(resp);
               }, function errorCallback(response) {
                alert(response.data.error.message);
              });

Tested using supervisor or node directly... my versions are node v4.2.2,

strongloop v5.0.1 (node v4.2.2)
├── strong-arc@1.8.4 (b7b568d)
├── strong-build@2.0.6 (d008a3e)
├── strong-deploy@3.1.2 (be6180a)
├── strong-mesh-models@8.1.0 (62e539b)
├── strong-pm@5.0.1 (b96f806)
├── strong-registry@1.1.5 (f46e58f)
├── strong-start@1.3.2 (1327018)
├─┬ strong-supervisor@3.3.1 (1e39220)
│ └── strong-agent@2.0.2 (4ea7ee9)
├── generator-loopback@1.13.0 (a884c0b)
├── node-inspector@0.7.4
└── nodefly-register@0.3.3
gholias commented 8 years ago

I found out that the record save was failing for another reason, but the message said the email was invalid. In my case was a problem related to a wrong Oracle field type.

Check the details of the error object, something like this:

if (err.details) {
    console.log("unknownServerError details: " + util.inspect(err.details.codes));
 }
mariohmol commented 8 years ago

Thanks a lot!!!

You are right.. it shows me a error in mysql... in my case was a column mapped that doesnt exists in database .. some default fields used in User that does not exists in my AccountUser table (in my case was realm column)

Anyway, would be better to have a different error message here rather than "email invalid", do u agree?

gholias commented 8 years ago

yes, I agree The error message make lost a lot of time trying to see what could be wrong with the values I was saving.

On Wed, Nov 25, 2015 at 11:20 AM, Mario Mol notifications@github.com wrote:

Thanks a lot!!!

You are right.. it shows me a error in mysql... in my case was a column mapped that doesnt exists in database .. the weird here is that this account-user.json was generated by sontrongloop discover...

Anyway, would be better to have a different error message here rather than "email invalid", do u agree?

— Reply to this email directly or view it on GitHub https://github.com/strongloop/loopback/issues/1803#issuecomment-159605218 .

Felipe Oliveira, Software Developer

http://www.felipeoliveira.me http://www.felipeoliveira.me

Amir-61 commented 8 years ago

Thanks for bringing this to our attention!

I'll label this issue as enhancement/feature to show better error messages.

Thanks

hanseilers commented 7 years ago

It's a year later and I still get the same issue. It says email not valid, but the actual error digging down is that the table has not been created.

What is the status on those better error messages?

ritch commented 7 years ago

This is a bug.. not sure why it was marked as a feature.

simoami commented 7 years ago

Just hit the same error and glad I found this thread. In my case, I attempted to simply create a second user with the same email. I used the stock POST /users with { email, password } as form data

Here's the full log:

3|APP      | Unhandled error for request POST /api/v1/users: ValidationError: The `user` instance is not valid. Details: `email` is invalid (value: "simo@xxxx.com"
).
3|APP      |     at /usr/src/app/node_modules/loopback-datasource-juggler/lib/dao.js:323:12
3|APP      |     at ModelConstructor.<anonymous> (/usr/src/app/node_modules/loopback-datasource-juggler/lib/validations.js:513:13)
3|APP      |     at ModelConstructor.next (/usr/src/app/node_modules/loopback-datasource-juggler/lib/hooks.js:83:12)
3|APP      |     at done (/usr/src/app/node_modules/loopback-datasource-juggler/lib/validations.js:510:25)
3|APP      |     at /usr/src/app/node_modules/loopback-datasource-juggler/lib/validations.js:588:7
3|APP      |     at ModelConstructor.<anonymous> (/usr/src/app/node_modules/loopback-datasource-juggler/lib/validations.js:382:5)
3|APP      |     at DestroyableTransform.allCb (/usr/src/app/node_modules/loopback-datasource-juggler/lib/dao.js:2016:7)
3|APP      |     at emitOne (events.js:96:13)
3|APP      |     at DestroyableTransform.emit (events.js:188:7)
3|APP      |     at /usr/src/app/node_modules/google-cloud/node_modules/through2/through2.js:19:12
3|APP      |     at _combinedTickCallback (internal/process/next_tick.js:67:7)
3|APP      |     at process._tickDomainCallback (internal/process/next_tick.js:122:9)

As @gholias mentioned, the real error is buried in the details error of the ValidationError object.

{ 
  name: 'ValidationError',
  message: 'The `user` instance is not valid. Details: `email` is invalid (value: "simo@xxxx.com").',
  statusCode: 422,
  details: { 
    context: 'user',
    codes: { email: [ 'uniqueness.Error: Connect Failed' ] },     <<<<<<<<  Real Error
    messages: Errors { email: [ 'is invalid' ] }
  }
} 
timlind commented 7 years ago

When an email address on a subclass of User is not unique, I'm getting an error message about another column not existing: UNIQUENESS.ERROR: COLUMN "HEIGHTINCHES" DOES NOT EXIST

This was happening because migration was failing somewhere else with a new required property on a column that had null values (you can allow nulls via the custom connector properties if needed btw).

simoami commented 7 years ago

@gholias @timlind @ritch

After I redefined the email property in my custom user.json as follows the error message improved:

    "email": {
      "type": "string",
      "index": {"unique": true}
    },

The new error is now much better:

{
  "error": {
    "statusCode": 422,
    "name": "ValidationError",
    "message": "The `user` instance is not valid. Details: `email` Email already exists (value: \"simo@****.com\").",
    "details": {
      "context": "user",
      "codes": {
        "email": [
          "uniqueness"
        ]
      },
      "messages": {
        "email": [
          "Email already exists"
        ]
      }
    }
  }
}

I hope this helps!

diversoft commented 7 years ago

the same error

the-freshlord commented 7 years ago

Getting this as well

virkt25 commented 7 years ago

Need to investigate to see the real cause of the issue (Connection Failed? Juggler? etc?) as it seems like an incorrect error message is being thrown OR is it actually a validation issue before it can be fixed.

osamasaeed commented 7 years ago

I have resolve this issue. assign null to all unnecessary fields of User model in your model. example:

 "credentials":null,
"challenges":null,
"realm":null,
"status": null,
"created": null,
"lastUpdated": null,

I hope this will work.

osamasaeed commented 7 years ago

assign null to unnecessary fields "credentials":null, "challenges":null, "realm":null, "status": null, "created": null, "lastUpdated": null

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Amir-61 commented 6 years ago

This is a bug and unresolved.

zegulas commented 6 years ago

I tried withDEBUG=* node . What I could see is that its actually an SQL error, but for some reason we get an incorrect validation error for email field.

Here is some log from the report:

Excerpt from the SQL error:

 code: 'ER_BAD_FIELD_ERROR',
  errno: 1054,
  sqlMessage: 'Unknown column \'gender\' in \'field list\'',
  sqlState: '42S22',
  index: 0,
  sql: 'SELECT `name`,`email`,`dob`,`gender`,`mobile_no`,`pickup_coordinates`,`destination_coordinates`,`time_range`,`availability`,`days_of_the_week`,`vehicle_type`,`vehicle_name`,`ratings`,`realm`,`username`,`password`,`credentials`,`challenges`,`emailVerified`,`verificationToken`,`status`,`created`,`lastUpdated`,`id` FROM `customer` WHERE `email`=\'example@gmail.com\' ORDER BY `id`' }

This error is clearly about unknown column name 'gender' but instead of that we get the following error:

Unhandled error for request POST /api/customers: ValidationError: The `customer` instance is not valid. Details: `email` is invalid (value: "example@gmail.com").
stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 6 years ago

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.