proxygen
|
#include <DynamicParser.h>
Classes | |
struct | ParserStack |
Public Types | |
enum | OnError { OnError::RECORD, OnError::THROW } |
Public Member Functions | |
DynamicParser (OnError on_error, const folly::dynamic *d) | |
folly::dynamic | releaseErrors () |
template<typename Fn > | |
void | optional (const folly::dynamic &key, Fn) |
template<typename Fn > | |
void | required (const folly::dynamic &key, Fn) |
template<typename Fn > | |
void | objectItems (Fn) |
template<typename Fn > | |
void | arrayItems (Fn) |
const folly::dynamic & | key () const |
const folly::dynamic & | value () const |
DynamicParser & | setAllowNonStringKeyErrors (bool b) |
Private Member Functions | |
template<typename Fn > | |
void | wrapError (const folly::dynamic *lookup_key, Fn) |
void | reportError (const folly::dynamic *lookup_k, const std::exception &ex) |
template<typename Fn > | |
void | parse (const folly::dynamic &key, const folly::dynamic &value, Fn fn) |
Private Attributes | |
OnError | onError_ |
ParserStack | stack_ |
bool | allowNonStringKeyErrors_ {false} |
Definition at line 229 of file DynamicParser.h.
|
strong |
|
inline |
Definition at line 241 of file DynamicParser.h.
void folly::DynamicParser::arrayItems | ( | Fn | fn | ) |
Like objectItems() – arrays are treated identically to objects with integer keys from 0 to size() - 1.
Definition at line 280 of file DynamicParser-inl.h.
References i, parse(), and folly::value().
Referenced by TEST().
|
inline |
The key currently being parsed (integer if inside an array). Throws if called outside of a parser callback.
Definition at line 283 of file DynamicParser.h.
References stack_.
Referenced by TEST().
void folly::DynamicParser::objectItems | ( | Fn | fn | ) |
Iterate over the current object's keys and values. Report each item's errors under its own key in a matching sub-object of "errors".
Definition at line 271 of file DynamicParser-inl.h.
References parse(), and folly::value().
Referenced by TEST().
void folly::DynamicParser::optional | ( | const folly::dynamic & | key, |
Fn | fn | ||
) |
Error-wraps fn(auto-converted key & value) if d[key] is set. The top-of-file docblock explains the auto-conversion.
Definition at line 244 of file DynamicParser-inl.h.
References folly::get_ptr(), parse(), and folly::value().
Referenced by TEST().
|
private |
Definition at line 307 of file DynamicParser-inl.h.
References folly::gen::guard(), folly::detail::invokeForKeyValue(), and stack_.
|
inline |
Once you finished the entire parse, returns a structured description of all parse errors (see top-of-file docblock). May ONLY be called once. May NOT be called if the parse threw any kind of exception. Returns an empty object for successful OnError::THROW parsers.
Definition at line 250 of file DynamicParser.h.
References stack_.
Referenced by checkItemParseError(), checkMaybeCoercedKeys(), checkXYKeyErrorsAndParseError(), and TEST().
|
private |
Definition at line 53 of file DynamicParser.cpp.
References allowNonStringKeyErrors_, folly::DynamicParser::ParserStack::errors(), folly::FATAL, folly::dynamic::object(), onError_, RECORD, stack_, THROW, folly::DynamicParser::ParserStack::throwErrors(), folly::detail::toPseudoJson(), and value().
void folly::DynamicParser::required | ( | const folly::dynamic & | key, |
Fn | fn | ||
) |
Definition at line 257 of file DynamicParser-inl.h.
References parse(), folly::detail::toPseudoJson(), and folly::value().
Referenced by checkMaybeCoercedKeys(), and TEST().
|
inline |
By default, DynamicParser's "nested" object coerces all keys to strings, whether from arrayItems() or from p.optional(some_int, ...), to allow errors be serialized to JSON. If you are parsing non-JSON dynamic objects with non-string keys, this is problematic. When set to true, "nested" objects will report integer keys for errors coming from inside arrays, or the original key type from inside values of objects.
Definition at line 302 of file DynamicParser.h.
References b, parse(), and folly::value().
Referenced by checkMaybeCoercedKeys().
|
inline |
The value currently being parsed (initially, the input dynamic). Throws if parsing nullptr, or parsing after releaseErrors().
Definition at line 290 of file DynamicParser.h.
References stack_.
Referenced by reportError(), and TEST().
|
private |
If fn
throws an exception, wrapError() catches it and inserts an enriched description into stack_.errors_. If lookup_key is non-null, reports a key lookup error in "key_errors", otherwise reportse a value error in "error".
Not public because that would encourage users to report multiple errors per input part, which is currently unsupported. It does not currently seem like normal user code should need this.
Definition at line 291 of file DynamicParser-inl.h.
|
private |
Definition at line 408 of file DynamicParser.h.
Referenced by reportError().
|
private |
Definition at line 406 of file DynamicParser.h.
Referenced by reportError().
|
private |
Definition at line 407 of file DynamicParser.h.
Referenced by reportError().