question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Model validation doesn't report the model it fails for

See original GitHub issue

Version: 2.1.3

Given a model with required name and description attributes, I’m seeing the following validation errors:

     ValidationError: name: is a required property, description: is a required property
      at Function.createValidationError (node_modules/objection/lib/model/Model.js:357:12)
      at parseValidationError (node_modules/objection/lib/model/AjvValidator.js:189:21)
      at AjvValidator.validate (node_modules/objection/lib/model/AjvValidator.js:78:19)
      at validate (node_modules/objection/lib/model/modelValidate.js:35:20)
      at Object.$validate (node_modules/objection/lib/model/Model.js:93:12)
      at GraphInsertAction._insert (node_modules/objection/lib/queryBuilder/graph/insert/GraphInsertAction.js:177:16)
      at GraphInsertAction._insertBatch (node_modules/objection/lib/queryBuilder/graph/insert/GraphInsertAction.js:48:16)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

Shouldn’t this error report which model it fails for? Seems like it’d be easier if multiple models are involved (test setup for example) to determine which one is the offending one, without requiring further debugging.

I’m imagining something like this for a model named Task:

     ValidationError (Task): name: is a required property, description: is a required property
      at Function.createValidationError (node_modules/objection/lib/model/Model.js:357:12)
      at parseValidationError (node_modules/objection/lib/model/AjvValidator.js:189:21)
      at AjvValidator.validate (node_modules/objection/lib/model/AjvValidator.js:78:19)
      at validate (node_modules/objection/lib/model/modelValidate.js:35:20)
      at Object.$validate (node_modules/objection/lib/model/Model.js:93:12)
      at GraphInsertAction._insert (node_modules/objection/lib/queryBuilder/graph/insert/GraphInsertAction.js:177:16)
      at GraphInsertAction._insertBatch (node_modules/objection/lib/queryBuilder/graph/insert/GraphInsertAction.js:48:16)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

2reactions
koskimascommented, Jan 24, 2021

ValidationError and NotFoundError now have a modelClass property.

1reaction
koskimascommented, Jan 26, 2021

@devinivy I fixed the issue and released a new version. Sorry about that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolve model validation failed errors in CloudFormation - AWS
When I create a resource with AWS CloudFormation, I receive a "Model Validation Failed" error in my stack events.
Read more >
Model validation in ASP.NET Core MVC | Microsoft Learn
Model validation occurs after model binding and reports errors where data doesn't conform to business rules. For example, a 0 is entered in ......
Read more >
Reporting Model Validation Errors in ASP.NET Core 2.0
During a model validation failure event, an instance of ValidationProblemDetails is filled in and sent out with Content-Type header set to ...
Read more >
BUG: validation doesn't run in model.save() if model ... - GitHub
This issue seems to be mitigated by calling the validateSync() function, but even so, it should NEVER write data failing to pass validation...
Read more >
Change the default error message in the model state binder ...
Model state represents errors that come from two subsystems: model binding and model validation. Errors that originate from model binding ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found