rapidjson icon indicating copy to clipboard operation
rapidjson copied to clipboard

RapidJSON is great, but the assertions make it too risky for production use

Open randolf opened this issue 2 years ago • 3 comments

Is there an easy way to change all the assertions that RapidJSON raises into C++ exceptions? It's not useful in its current state because user-supplied JSON data that's missing an expected value, or said value is/isn't an array, results in the entire application (along with all its threads) abruptly terminating.

Thanks.

randolf avatar May 25 '23 05:05 randolf

RapidJSON is perfectly fine for production and is used by tons of stuff... If you want to deal with optional or potentially missing or mistyped data, then you should rely on stuff like HasMember()/FindMember() or IsObject/Array/XXX(), and prefer the use of iterators rather than direct access. When used right, this doesn't impact performance, since ultimately it's doing the same kind of lookup/indexing as direct access does. If YOUR code is making assumptions on data that's not there, don't blame the library that can't find it...

Cheers!

moretromain avatar May 25 '23 06:05 moretromain

I'll look into FindMember() and friends, thanks.

I'm not making assumptions about the data, and I'm not blaming the library. I just wanted to know if there's a way to change the library's behaviour from raising assertions to throwing exceptions, so that I can use this library in production applications -- assertions that terminate the entire process are fine for development and certain types of testing, but it's not acceptable for non-technical end-users, which is why I want to know if it's possible (if it isn't possible, then I'll have to look at other options like forking the library to fix it, or using other libraries if that's a major undertaking, etc.).

So, is there a way to change the library's behaviour to throwing exceptions instead of raising assertions (that terminate the entire application)?

randolf avatar May 25 '23 06:05 randolf