sails-hook-validation icon indicating copy to clipboard operation
sails-hook-validation copied to clipboard

Not adding custom messages in Sails v1.0.0-36

Open LucasMcL opened this issue 6 years ago • 4 comments

Hi. I can't seem to get this hook to work in Sails v1.0.0-36. Here's what I have.

Model EstablishmentClue

module.exports = {

  attributes: {

    name: {
      columnName: 'name',
      type: 'string',
      required: true,
    },

  ...

  },

  validationMessages: {
    name: {
      required: 'Name is required',
    },
  },

};

In sails console:

sails> EstablishmentClue.create({}).exec(console.log);
Error (E_UNKNOWN) :: Encountered an unexpected error
    at new WLError (/Users/Lucas/CompuDharma/treasuretown/treasuretown_web/node_modules/sails-hook-validation/node_modules/waterline/lib/waterline/error/WLError.js:26:15)
    at Object.module.exports.patch (/Users/Lucas/CompuDharma/treasuretown/treasuretown_web/node_modules/sails-hook-validation/lib/WLValidationError.js:8:13)
    at /Users/Lucas/CompuDharma/treasuretown/treasuretown_web/node_modules/sails-hook-validation/lib/create.js:66:48
    at _.extend._WLModel (/Users/Lucas/CompuDharma/treasuretown/treasuretown_web/node_modules/waterline/lib/waterline/methods/create.js:155:20)
    at parley (/Users/Lucas/CompuDharma/treasuretown/treasuretown_web/node_modules/parley/lib/parley.js:111:5)
    at newConstructor.create (/Users/Lucas/CompuDharma/treasuretown/treasuretown_web/node_modules/waterline/lib/waterline/methods/create.js:130:10)
    at newConstructor.create (/Users/Lucas/CompuDharma/treasuretown/treasuretown_web/node_modules/sails-hook-validation/lib/create.js:47:14)
    at module.exports.Deferred.exec (/Users/Lucas/CompuDharma/treasuretown/treasuretown_web/node_modules/sails-hook-validation/node_modules/waterline/lib/waterline/query/deferred.js:477:16)
    at repl:1:30
    at ContextifyScript.Script.runInThisContext (vm.js:44:33)
    at REPLServer.defaultEval (repl.js:239:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:433:10)
    at emitOne (events.js:120:20)
    at REPLServer.emit (events.js:210:7)
    at REPLServer.Interface._onLine (readline.js:278:10)
    at REPLServer.Interface._line (readline.js:625:8)
    at REPLServer.Interface._ttyWrite (readline.js:904:14)
    at REPLServer.self._ttyWrite (repl.js:502:7)
    at ReadStream.onkeypress (readline.js:157:10)
    at emitTwo (events.js:125:13)
    at ReadStream.emit (events.js:213:7)
    at emitKeys (internal/readline.js:417:14)
    at emitKeys.next (<anonymous>)
    at ReadStream.onData (readline.js:1005:36)
    at emitOne (events.js:115:13)
    at ReadStream.emit (events.js:210:7)
    at addChunk (_stream_readable.js:250:12)
    at readableAddChunk (_stream_readable.js:237:11)
    at ReadStream.Readable.push (_stream_readable.js:195:10)
    at TTY.onread (net.js:586:20)

When I log error.toJSON() I get this:

{ error: 'E_UNKNOWN',
  status: 500,
  summary: 'Encountered an unexpected error',
  Errors: undefined }

Any thoughts on why the custom error messages aren't attaching?

LucasMcL avatar Sep 28 '17 19:09 LucasMcL

I have the same issue as well. Also using version v1 of Sails.

ghost avatar Sep 30 '17 13:09 ghost

This is because in WLValidationError.js, the function toJSON/toPOJO is never called

izanagi1995 avatar Apr 09 '18 17:04 izanagi1995

asJSON[errorKey] = this.Errors; this.Errors is not defined in WLValidationError.js

izanagi1995 avatar Apr 09 '18 18:04 izanagi1995

I am having same issue. I think its a long pending issue.

prof-jagpreet avatar Jun 09 '18 09:06 prof-jagpreet