Skip to content

Conversation

@Wi1l-B0t
Copy link
Contributor

Description

If too few arugments, the error code shoud be InvalidParam, but got an unexpected exception info.

{"jsonrpc":"2.0","id":1,"error":{"code":-2146233086,"message":"Index was out of range. Must be non-negative and less than the size of the collection.

After fix:

{"jsonrpc":"2.0","id":1,"error":{"code":-32602,"message":"Invalid params - Too few arguments. Expected at least 1 but got 0.

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@Jim8y
Copy link
Contributor

Jim8y commented Jul 19, 2025

would be great if you can make them use RpcMethodWithParams, but this pr is also good for me.

public static void ThrowIfTooFew(JArray @params, int requiredArgs, RpcError error)
{
if ((@params is null && requiredArgs > 0) || (@params is not null && @params.Count < requiredArgs))
throw new RpcException(error.WithData($"Too few arguments. Expected at least {requiredArgs} but got {@params?.Count ?? 0}."));
Copy link
Contributor

Choose a reason for hiding this comment

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

i think this type of exception messgae is too general, would be better to specify which is missing for dedicated rpc methods. but better than nothing.

[RpcMethod]
protected internal virtual JToken InvokeFunction(JArray _params)
{
RpcException.ThrowIfTooFew(_params, 2, RpcError.InvalidParams); // ScriptHash, Operation
Copy link
Contributor

Choose a reason for hiding this comment

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

params ? _params[2]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What does params ? _params[2] mean?

@Wi1l-B0t
Copy link
Contributor Author

Wi1l-B0t commented Jul 19, 2025

would be great if you can make them use RpcMethodWithParams, but this pr is also good for me.

I will do it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants