pboettch / json-schema-validator

JSON schema validator for JSON for Modern C++
Other
470 stars 135 forks source link

Suggestion - Extend Errormessage for programming errors #199

Closed LukeKitt closed 2 years ago

LukeKitt commented 2 years ago

Hi,

TLDR: I made a stupid coding mistake and the error message completely confused me.

I created an Instance of an validator(on the stack), saved the address and the instance went out of scope (got destroyed). Later I accessed the "validator" address and tried a validation. The Error returned was : Validation failed, here is why: At of "" - no file found serving requested root-URI. Because of that I searched for the solution at the wrong end.

Also the compiler didn't get the mistake at compiletime so no warning was thrown.

So my suggestion is to append to the error message [...] or this instance was destroyed (json-validator.cpp:295) Possibly that saves future persons that make the same mistake some time.

Best regards

pboettch commented 2 years ago

If you think over your request (and your proposed solution) you'll quickly understand that this isn't possible. Where should this library store the information that the object has been freed? In the memory which has been freed? And then read from it?

Using an object which has been destroyed should lead to a "use-after-free" condition and finish with segmentation-fault. That this doesn't happen in your context is pure chance. Maybe your compiler could have warned you about using a "local reference" in a global context.

LukeKitt commented 2 years ago

Yeah, you are right. It doesn't make sense because it could trigger anywhere an error. Normally a Seg-Fault would be expected and clearly would indicate the problem. Best would be probably to recreate a small example of it and then suggest to make a compiler warning out of it. That would be the correct place to catch that problem. Thank you nevertheless