Haven’t really looked at implementation yet, but can documentation be updated to say what happens with type mismatches?
This sound like a bug in the source code, so I don’t think it makes sense to document unreachable or unexpected code paths. Generally, in the RPC server non-fatal bugs are expected to throw an internal bug message.
I haven’t looked at the code, but types of arguments passed in by the user should be checked before m_fun is run. m_fun, and thus, Arg()
isn’t run when the types passed in by the user mismatch the ones in the documentation. If Arg()
specifies the wrong type, the getter will throw. Currently all getters are univalue getters, so they’ll throw the univalue internal exception. (This is the current behavior and preserved)
I think this is fine as-is, but I am happy to change it to something else, for example:
- Re-implement the type check and throw a new, special exception. (This will be a change in “behavior”, or rather “bug behavior”)
- Implement a compile-time json and use the compiler to avoid the case altogether, or alternatively, use clang-tidy to do it?
Also might be nice to add a short examples here showing what equivalent low level code is so developers can know how to use this helper and interpret it.
The diff in this commit should explain it. I’ve also added docs about the internals (isNull
check and fallback to RPCArg::m_fallback)
to support arrays/objects
Yeah, it should be possible to return an object whose operator[]
is defined. Would it be fine to do this in a follow-up?
to enforces only expected types are passed at compile time
Maybe as follow-up, unless the patch is trivial?
to enforce default not requested when there is no default at compile time
This is already done, no?
to somehow be compatible with luke’s
Not sure about adding dead code, but once and if it is needed, it should be trivial to implement by mapping the types to a Arg<std::variant<int, bool>>(1)
in C++ code. However, I am not sure if this is worth it, when it is only used once. Might as well use the “legacy” method for now?