json-schema-validator icon indicating copy to clipboard operation
json-schema-validator copied to clipboard

Optional error reporting for logical combinations

Open EShirykalov opened this issue 5 years ago • 11 comments

Hello,

In current version class logical_combination reports generic error after evaluation of all variants of subschema. It would be nice to add an option to log errors from individual subschemas as well if overall validation fails.

EShirykalov avatar Apr 17 '20 21:04 EShirykalov

This was existing in the first version of the library, which was otherwise so much worse.

The problem is that with the error message callback you'd get message of failing combination-items which would be difficult to understand.

And I assume furthermore you would not want the error messages of failing combination-items if another one would be successful. So we would need to filter.

I might try something.

pboettch avatar Apr 18 '20 06:04 pboettch

I tried something and I have it on a local branch. Note to myself.

pboettch avatar Jun 12 '20 15:06 pboettch

Hi @pboettch , did you ever revisit this issue on your local branch?

gabor-varga avatar Jan 28 '21 09:01 gabor-varga

@gabor-varga Yes I still have it on local. Would you mind testing and using it to see whether it fills the needs? I have to say it's quite verbose and only human readable.

pboettch avatar Jan 28 '21 10:01 pboettch

I pushed an 'error-check'-branch which contains a change printing sub-schema errors if the logical-combination has failed.

pboettch avatar Jan 28 '21 10:01 pboettch

Thanks @pboettch , I will check it. I basically want to find a way to print meaningful error messages on validation error that lets the user debug their config. We have quite complex schemas with many one_of.

gabor-varga avatar Jan 28 '21 14:01 gabor-varga

Thank you @pboettch , I will try to use and test it as well.

ghost avatar Jan 28 '21 22:01 ghost

Hi @pboettch, have there been there any updates on the issue since January? Have you considered merging the branch to master? Also, with my github account, I can't find the branch called error-check, has it been deleted since, or is it private?

iksemyonov avatar Nov 15 '21 11:11 iksemyonov

It seems I forgot to push it.

pboettch avatar Nov 15 '21 12:11 pboettch

Done.

pboettch avatar Nov 15 '21 12:11 pboettch

https://github.com/pboettch/json-schema-validator/tree/error-check

pboettch avatar Dec 10 '21 15:12 pboettch

Hi @pboettch, I've tested a bit your error-check branch and found it quite useful. Do you plan on merging this to master?

lpelerin avatar Apr 17 '23 15:04 lpelerin

Hi @pboettch,

I also checked the error-check branch, but the solution is not exactly what we were looking for.

I've found two issues:

  • The additional information will be generated only for the first logical combination level. E.g. if there is an anyOf, and inside it an another anyOf, the messages will be generated only for the first anyOf. There will be no detailed error messages generated for the deeper anyOf levels. (Or for any logical combination types).
  • For custom error handlers it is not possible to access the pointer and the instance informations about the error, since they will be all packed into the message.

I have a proposal for fixing these issues and have all of the logical combination error messages: https://github.com/zecoaat/json-schema-validator

For the default error handler it works like earlier - only the root logical combination error will be thrown.

However, if you install a custom error handler, you can get all the details about the various cases:

no subschema has succeeded, but one of them is required to validate. Type: anyOf, number of failed subschemas: 3
[combination: anyOf / case#0] no subschema has succeeded, but one of them is required to validate. Type: anyOf, number of failed subschemas: 2
[combination: anyOf / case#0] [combination: anyOf / case#0] instance is below minimum of 5
[combination: anyOf / case#0] [combination: anyOf / case#1] instance is not a multiple of 2.0
[combination: anyOf / case#1] unexpected instance type
[combination: anyOf / case#2] unexpected instance type

(You can find the schema used for this test in the fork-project in tests.)

Please review the changes and consider merging this fork into the upstream project. Thank you in advance, Jimmy

zecoaat avatar Dec 19 '23 14:12 zecoaat

@zecoaat Do not hesite to make a pull-request here! Your work's output looks nice.

pboettch avatar Dec 31 '23 16:12 pboettch

@pboettch I created the pull request for the modifications: https://github.com/pboettch/json-schema-validator/pull/310

zecoaat avatar Jan 03 '24 13:01 zecoaat

Fixed with #310. Thanks @zecoaat .

pboettch avatar Feb 07 '24 13:02 pboettch