Skip to content

RPC: make RPCResult::MatchesType return useful errors - #26887

Merged
maflcko merged 1 commit into
bitcoin:masterfrom
ajtowns:202301-rpc-matchestype
Jan 20, 2023
Merged

maflcko merged 1 commit into
bitcoin:masterfrom
ajtowns:202301-rpc-matchestype

Conversation

@ajtowns

@ajtowns ajtowns commented Jan 13, 2023

Copy link
Copy Markdown
Contributor

Currently if you don't correctly update the description of the return value for an RPC call, you essentially just get an assertion failure with no useful information; this generates a description of the problems instead.

@DrahtBot

DrahtBot commented Jan 13, 2023 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK MarcoFalke
Concept ACK brunoerg

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #25429 (refactor: Avoid UniValue copies by MarcoFalke)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@ajtowns

ajtowns commented Jan 13, 2023

Copy link
Copy Markdown
Contributor Author

eg if I garble up the results of getdeploymentinfo, and run rpc_blockchain.py, prior to this PR, I just get:

test_framework.authproxy.JSONRPCException: Internal bug detected: "std::any_of(m_results.m_results.begin(), m_results.m_results.end(), [&ret](const RPCResult& res) { return res.MatchesType(ret); })"
rpc/util.cpp:584 (HandleRequest)
Bitcoin Core v24.99.0-38d883a41078
Please report this issue here: https://github.com/bitcoin/bitcoin/issues

with this PR, I instead get:

test_framework.authproxy.JSONRPCException: Internal bug detected: RPC call "getdeploymentinfo" returned incorrect type:
{
    "deployments": {
        "testdummy": {
            "bip9": {
                "awesomeness": "unexpected key",
                "status_next": "non-optional key missing",
                "statistics": {
                    "period": "expected number got null",
                    "threshold": "expected number got string"
                }
            }
        },
        "taproot": {
            "bip9": {
                "awesomeness": "unexpected key",
                "status_next": "non-optional key missing"
            }
        }
    }
}
Bitcoin Core v24.99.0-51b4318e76d3-dirty
Please report this issue here: https://github.com/bitcoin/bitcoin/issues

which seems much more helpful for fixing the problem.

cc @MarcoFalke

@maflcko maflcko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Concept ACK

Comment thread src/rpc/util.h Resolved
Comment thread src/rpc/util.cpp Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. Wouldn't it be better to use one of the existing checks or formatters from util/check?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe? Could just use StrFormatInternalBug I guess, but the file/line/func info would be kind of misleading as to where the bug is?

(As it is, it backports cleanly to 24.0, which was convenient for what I was trying to debug)

@brunoerg brunoerg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

It had helped me to save a lot of time recently btw :)

@maflcko maflcko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one typo. Also, in the presence of bugs it could be confusing to call something "expected". Instead, it could make more sense to just say there is an error and mention the doc-type and the result-type.

ACK 94adb442fac9da04063a57897b44a9623c4fe39e 🔎

Show signature

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

ACK 94adb442fac9da04063a57897b44a9623c4fe39e 🔎
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUjBLAv+KtPRXStO2Xnup245psxH0FXERsW5S+crdH2b/fqi+vWqAi0KhOXo6BSw
LMANJug1Ynkx+b9Dr8+hBVbTS4EMSHx3LeabuUdVGVPZKBhVV/+PLhT8E0nnCHy9
Yj0c4s+QXkk0Y1bhM7obILGlohrlVRtJ74btQ7ZyUaM7sZnrHAnBr1FkiQvsUA7f
X5TTm1gwC80akEkRRlpf1UkdAjU0O8hrRdg2oIVngj4ADPm03wFAfa3W1b+b0Wyd
wmQgfuzntpAifsZ0KhxA2hBObCmai/7YArkjGnuDMnpi2PnxIk2KxKllCmN6jAOx
fpk+cZ+sHX6XjxFWRnuS7WI2v/NwVe144526u9dK00qAqjwCzHCgwEt1wJm1jqsn
rHELAjaqPkfXGrOnujw08TGeQ+b+FThcxqduTPhfxyFzeB4/lJX+oOKcxcqdjKef
gzxxz/wbJmJEcFCfWbLXE7+bSfX/9hs+XRkv+q75+7TfjNkyhhWM4VYGFOI0EaQl
fRyWhmTw
=3pbv
-----END PGP SIGNATURE-----

Comment thread src/rpc/util.h Resolved
Comment thread src/rpc/util.cpp Resolved
Comment thread src/rpc/util.cpp Resolved
Comment thread src/rpc/util.cpp Resolved
Comment thread src/rpc/util.cpp Resolved
Comment thread src/rpc/util.cpp Resolved
@ajtowns
ajtowns force-pushed the 202301-rpc-matchestype branch from 94adb44 to 3d1a4d8 Compare January 19, 2023 20:34
@ajtowns

ajtowns commented Jan 19, 2023

Copy link
Copy Markdown
Contributor Author

Took @MarcoFalke's suggestions (albeit with some wording changes)

@maflcko

maflcko commented Jan 20, 2023

Copy link
Copy Markdown
Member

Very nice.

re-ACK 3d1a4d8 🌷

Show signature

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

re-ACK 3d1a4d8a45cd91bdfe0ef107c2e9c5e882b34155 🌷
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUh5ogwAqFK3gSDeY/HTfF78yN2cKwY7LyA3KhtWtki4DRFiJ9ouLVEnvo+U+n9S
jLrNMgMC9j3m79ra7xKG4chBq0mQDiMSO3aLvJNDt/elq9gJLUHjL9fW/0ZaTdlb
jSNOWjZ+PjycMg45K1yLTVEa8QS+1tCoF6yb+80lCXWWZvLn34iTp5FB7OM/V7kL
ltZRJ5uQFg0k4rR05C7m6ovr1h9XrvEEEd7sUV7ODrHKRHEKRTZsMOJZEC6LT02a
xQi92XHQOtxMynXMNPlJEFEr9SRtvumukkbLrV1v4WJB8rcaUlmV7PCKHpB2OHoJ
JIZe7tjNNxxF1wMgMJkHBWT6X+ZGXMkd5QqYcxuj1Jyz6hw++HVkgHg8Ectiu7zx
gMh3efJWD2XUp8DGSvxw31AVV/xcNLz54eSazTS4B42lDYL8ikA+3AVg5bjkRZkI
DCjmFQH56tzc61OKo3ROQC2/cf4pO35i91zijCWmcGMFhYx3/Ln+F7P6pChqHZ1o
OYXNIklr
=nm1n
-----END PGP SIGNATURE-----

@maflcko
maflcko merged commit eebc24b into bitcoin:master Jan 20, 2023
Comment thread src/rpc/util.cpp
}

bool RPCResult::MatchesType(const UniValue& result) const
static const std::optional<UniValue::VType> ExpectedType(RPCResult::Type type)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: const is confusing and thus wrong?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #26929

@bitcoin bitcoin locked and limited conversation to collaborators Jan 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants