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

Signup.pug not displaying Sequelize error (even with the fix) #2485

Open
1 task done
nstuyvesant opened this issue Feb 2, 2017 · 6 comments
Open
1 task done

Signup.pug not displaying Sequelize error (even with the fix) #2485

nstuyvesant opened this issue Feb 2, 2017 · 6 comments

Comments

@nstuyvesant
Copy link
Contributor

nstuyvesant commented Feb 2, 2017

  • I understand that GitHub issues are not for tech support, but for questions specific to this generator, bug reports, and feature requests.
Item Version
generator-angular-fullstack 4.1.2
Node 6.94
npm 4.1.2
Operating System OS X 10
Item Answer
Transpiler Babel
Markup Pug
CSS SCSS
Bootstrap Y
UI-Bootstrap Y
Router ui-router
Client Tests Mocha
DB PostgresSQL 9.6.1 via Sequelize
Auth Y

Still digging into the resolution but noticed that the generated signup.pug is setup to handle Mongoose errors but has some issues with displaying the error from Sequelize.

To see what I'm talking about,

  1. Scaffold a project out using my settings above with PostgreSQL 9.6.1
  2. gulp serve
  3. Go to the signup page
  4. Try to create a local user that already exists in the database like [email protected].

What you'll see is that the email address field is correctly highlighted but the error passed back from server/api/user/user.controller.js:create isn't displayed in vm.errors.email in signup.pug. Also, the input attribute "mongoose-error" should probably be called "sequelize-error" if filters.sequelizeModels.

Here's the error output:

{ SequelizeUniqueConstraintError: A user with that email address already exists.
    at Query.formatError (/Users/nates/Documents/Development/shy/node_modules/sequelize/lib/dialects/postgres/query.js:321:18)
    at query.on.err (/Users/nates/Documents/Development/shy/node_modules/sequelize/lib/dialects/postgres/query.js:92:21)
    at emitOne (events.js:96:13)
    at emit (events.js:188:7)
    at NativeQuery.handleError (/Users/nates/Documents/Development/shy/node_modules/pg/lib/native/query.js:66:10)
    at after (/Users/nates/Documents/Development/shy/node_modules/pg/lib/native/query.js:84:19)
    at onError (/Users/nates/Documents/Development/shy/node_modules/pg-native/index.js:160:5)
    at g (events.js:291:16)
    at emitOne (events.js:101:20)
    at emit (events.js:188:7)
    at Client._readError (/Users/nates/Documents/Development/shy/node_modules/pg-native/index.js:81:8)
    at Client._read (/Users/nates/Documents/Development/shy/node_modules/pg-native/index.js:121:19)
    at emitNone (events.js:86:13)
    at PQ.emit (events.js:185:7)
From previous event:
    at Query.run (/Users/nates/Documents/Development/shy/node_modules/sequelize/lib/dialects/postgres/query.js:78:12)
    at retry (/Users/nates/Documents/Development/shy/node_modules/sequelize/lib/sequelize.js:564:32)
    at /Users/nates/Documents/Development/shy/node_modules/retry-as-promised/index.js:40:21
    at retryAsPromised (/Users/nates/Documents/Development/shy/node_modules/retry-as-promised/index.js:30:10)
    at Promise.resolve.then.connection (/Users/nates/Documents/Development/shy/node_modules/sequelize/lib/sequelize.js:564:14)
From previous event:
    at Sequelize.query (/Users/nates/Documents/Development/shy/node_modules/sequelize/lib/sequelize.js:561:7)
    at QueryInterface.insert (/Users/nates/Documents/Development/shy/node_modules/sequelize/lib/query-interface.js:472:27)
    at Promise.try.then.then.then (/Users/nates/Documents/Development/shy/node_modules/sequelize/lib/model.js:3385:56)
    at runCallback (timers.js:649:20)
    at tryOnImmediate (timers.js:622:5)
    at processImmediate [as _immediateCallback] (timers.js:594:5)
From previous event:
    at model.save (/Users/nates/Documents/Development/shy/node_modules/sequelize/lib/model.js:3365:8)
    at create (/Users/nates/Documents/Development/shy/server/api/user/user.controller.js:60:18)
    at Layer.handle [as handle_request] (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/route.js:131:13)
    at Route.dispatch (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/layer.js:95:5)
    at /Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:277:22
    at Function.process_params (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:330:12)
    at next (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:271:10)
    at Function.handle (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:176:3)
    at router (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:46:12)
    at Layer.handle [as handle_request] (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:312:13)
    at /Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:280:7
    at Function.process_params (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:330:12)
    at next (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:271:10)
    at Layer.handle [as handle_request] (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/layer.js:91:12)
    at trim_prefix (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:312:13)
    at /Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:280:7
    at Function.process_params (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:330:12)
    at next (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:271:10)
    at checkCsrf (/Users/nates/Documents/Development/shy/node_modules/lusca/lib/csrf.js:81:13)
    at /Users/nates/Documents/Development/shy/node_modules/lusca/index.js:48:21
    at hsts (/Users/nates/Documents/Development/shy/node_modules/lusca/lib/hsts.js:25:9)
    at /Users/nates/Documents/Development/shy/node_modules/lusca/index.js:48:21
    at xframe (/Users/nates/Documents/Development/shy/node_modules/lusca/lib/xframes.js:12:9)
    at /Users/nates/Documents/Development/shy/node_modules/lusca/index.js:48:21
    at xssProtection (/Users/nates/Documents/Development/shy/node_modules/lusca/lib/xssprotection.js:16:9)
    at /Users/nates/Documents/Development/shy/node_modules/lusca/index.js:48:21
    at lusca (/Users/nates/Documents/Development/shy/node_modules/lusca/index.js:53:9)
    at Layer.handle [as handle_request] (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:312:13)
    at /Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:280:7
    at Function.process_params (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:330:12)
    at next (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:271:10)
    at /Users/nates/Documents/Development/shy/node_modules/express-session/index.js:489:7
    at /Users/nates/Documents/Development/shy/node_modules/express-sequelize-session/lib/e4store.js:58:53
From previous event:
    at E4Store.get (/Users/nates/Documents/Development/shy/node_modules/express-sequelize-session/lib/e4store.js:56:12)
    at session (/Users/nates/Documents/Development/shy/node_modules/express-session/index.js:460:11)
    at Layer.handle [as handle_request] (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:312:13)
    at /Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:280:7
    at Function.process_params (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:330:12)
    at next (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:271:10)
    at initialize (/Users/nates/Documents/Development/shy/node_modules/passport/lib/middleware/initialize.js:53:5)
    at Layer.handle [as handle_request] (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:312:13)
    at /Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:280:7
    at Function.process_params (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:330:12)
    at next (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:271:10)
    at cookieParser (/Users/nates/Documents/Development/shy/node_modules/cookie-parser/index.js:70:5)
    at Layer.handle [as handle_request] (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:312:13)
    at /Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:280:7
    at Function.process_params (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:330:12)
    at next (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:271:10)
    at methodOverride (/Users/nates/Documents/Development/shy/node_modules/method-override/index.js:79:5)
    at Layer.handle [as handle_request] (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:312:13)
    at /Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:280:7
    at Function.process_params (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:330:12)
    at next (/Users/nates/Documents/Development/shy/node_modules/express/lib/router/index.js:271:10)
    at /Users/nates/Documents/Development/shy/node_modules/body-parser/lib/read.js:129:5
    at invokeCallback (/Users/nates/Documents/Development/shy/node_modules/raw-body/index.js:262:16)
    at done (/Users/nates/Documents/Development/shy/node_modules/raw-body/index.js:251:7)
    at IncomingMessage.onEnd (/Users/nates/Documents/Development/shy/node_modules/raw-body/index.js:307:7)
    at emitNone (events.js:86:13)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)
  name: 'SequelizeUniqueConstraintError',
  errors: 
   [ ValidationErrorItem {
       message: 'A user with that email address already exists.',
       type: 'unique violation',
       path: 'email',
       value: '[email protected]' } ],
  fields: { email: '[email protected]' },
  parent: 
   { Error: ERROR:  duplicate key value violates unique constraint "Users_email_key"
   DETAIL:  Key (email)=([email protected]) already exists.
   
       at Client._readError (/Users/nates/Documents/Development/shy/node_modules/pg-native/index.js:80:13)
       at Client._read (/Users/nates/Documents/Development/shy/node_modules/pg-native/index.js:121:19)
       at emitNone (events.js:86:13)
       at PQ.emit (events.js:185:7)
     severity: 'ERROR',
     sqlState: '23505',
     messagePrimary: 'duplicate key value violates unique constraint "Users_email_key"',
     messageDetail: 'Key (email)=([email protected]) already exists.',
     sourceFile: 'nbtinsert.c',
     sourceLine: '433',
     sourceFunction: '_bt_check_unique',
     sql: 'INSERT INTO "Users" ("_id","role","passwordHash","lastName","firstName","email","optOut","phone","provider","createdAt","updatedAt") VALUES (DEFAULT,\'student\',E\'\\\\x246172676f6e326924763d3139246d3d33323736382c743d342c703d312432354d7a6c624a6c6c6f7a6e562f337a6650534f6841247876422b437450454a57395272425664506f756f71635644736e64534d5864345a476f6a4870514b6a65590000000000000000000000000000000000000000000000000000000000000000\',\'Severance\',\'Alin\',\'[email protected]\',false,\'321-323-3232\',\'local\',\'2017-02-02 04:15:01.732 +00:00\',\'2017-02-02 04:15:01.732 +00:00\') RETURNING *;' },
  original: 
   { Error: ERROR:  duplicate key value violates unique constraint "Users_email_key"
   DETAIL:  Key (email)=([email protected]) already exists.
   
       at Client._readError (/Users/nates/Documents/Development/shy/node_modules/pg-native/index.js:80:13)
       at Client._read (/Users/nates/Documents/Development/shy/node_modules/pg-native/index.js:121:19)
       at emitNone (events.js:86:13)
       at PQ.emit (events.js:185:7)
     severity: 'ERROR',
     sqlState: '23505',
     messagePrimary: 'duplicate key value violates unique constraint "Users_email_key"',
     messageDetail: 'Key (email)=([email protected]) already exists.',
     sourceFile: 'nbtinsert.c',
     sourceLine: '433',
     sourceFunction: '_bt_check_unique',
     sql: 'INSERT INTO "Users" ("_id","role","passwordHash","lastName","firstName","email","optOut","phone","provider","createdAt","updatedAt") VALUES (DEFAULT,\'student\',E\'\\\\x246172676f6e326924763d3139246d3d33323736382c743d342c703d312432354d7a6c624a6c6c6f7a6e562f337a6650534f6841247876422b437450454a57395272425664506f756f71635644736e64534d5864345a476f6a4870514b6a65590000000000000000000000000000000000000000000000000000000000000000\',\'Severance\',\'Alin\',\'[email protected]\',false,\'321-323-3232\',\'local\',\'2017-02-02 04:15:01.732 +00:00\',\'2017-02-02 04:15:01.732 +00:00\') RETURNING *;' },
  sql: 'INSERT INTO "Users" ("_id","role","passwordHash","lastName","firstName","email","optOut","phone","provider","createdAt","updatedAt") VALUES (DEFAULT,\'student\',E\'\\\\x246172676f6e326924763d3139246d3d33323736382c743d342c703d312432354d7a6c624a6c6c6f7a6e562f337a6650534f6841247876422b437450454a57395272425664506f756f71635644736e64534d5864345a476f6a4870514b6a65590000000000000000000000000000000000000000000000000000000000000000\',\'Severance\',\'Alin\',\'[email protected]\',false,\'321-323-3232\',\'local\',\'2017-02-02 04:15:01.732 +00:00\',\'2017-02-02 04:15:01.732 +00:00\') RETURNING *;' }

Saw that there was a fix for this but it didn't work for me.

Thanks,
Nate

@nstuyvesant nstuyvesant changed the title Signup.pug is a little too Mongoose-centric Signup.pug not displaying Sequelize error (even with the fix) Feb 2, 2017
@stherrienaspnet
Copy link
Collaborator

Hello Nate, i made the last change to fixe the sequelize error not displayed correctly. I dont know anything about pug, can you look for my changes to see if you can bring it for pug? I will take a look on my side.

@stherrienaspnet
Copy link
Collaborator

Nate, today i try to follow your steps to reproduce your issue.

@stherrienaspnet
Copy link
Collaborator

I mean i will try... when i have a chance :)

@nstuyvesant
Copy link
Contributor Author

Thanks! Seems as though the error I get back from Sequelize 4.0.0-2 are structured a little differently than expected. The angular.forEach seems to loop through a fields array. In my case, the fields property returned was just an object:
fields: { email: '[email protected]' }

But the .errors property has an array that seems to address my needs:

errors: 
   [ ValidationErrorItem {
       message: 'A user with that email address already exists.',
       type: 'unique violation',
       path: 'email',
       value: '[email protected]' } ]

In signup.controller.js, I changed the catch to look like this:

        .catch(err => {
          err = err.data;
          this.errors = {}; // reset to only the latest errors

          // Update validity of form fields that match the sequelize errors
          if(err.name) {
            for(let error of err.errors) { // leverage ES6's for/of instead of angular.forEach
              form[error.path].$setValidity('sequelize', false);
              this.errors[error.path] = error.message;
            }
          }
        });

and everything works OK now. I would submit a PR but I'm wondering if the structure of the error is unique to Sequelize 4.0.0-2 so perhaps not widely applicable?

@stherrienaspnet
Copy link
Collaborator

stherrienaspnet commented Feb 3, 2017 via email

@stherrienaspnet
Copy link
Collaborator

Hello Nate,
You have a good point there. If you have some time to verify sequelize error structure on several version to see if your fix is widely applicable as you said this would be great. Unfortunately i'm still working on generator modification to integrate fully i18n.

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

2 participants