Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate and log when an unrecognized parameter/flag is used #7331

Conversation

wugalde19
Copy link
Contributor

@wugalde19 wugalde19 commented Aug 15, 2024

Resolves #6942

Changes

Changes made into src/Nethermind/Nethermind.Runner/Program.cs

  • Add a function to load all possible flags/params/arguments to be used and put them on a hash
    • The hash is initialized with the default flags allowed in the app and not related to flags in config files
  • Add a function to validate current args against the hash generated
  • Call the validation function into Run so that we initialize the app and validate before start running most of the logic.

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

Notes on testing

I did not see any test file for Program.cs files

Documentation

Requires documentation update

  • Yes
  • No

Requires explanation in Release Notes

  • Yes
  • No

Remarks

I recorded a video showing how it works and the error log is displayed when the argument/option/flag used is not valid and when it is valid.
Also, the cases where no flag is provided and when a default app flag (like --help) is provided, and when we try using duplicate arguments

https://www.loom.com/share/0ac1011bac1247b992a9fbadba9e5b26?sid=eb48d13b-961e-490e-a1ff-5fe51a2580b0

List of commands used:

# Should work
./publish/nethermind --help

# Should work
./publish/nethermind -v

# Should work
./publish/nethermind

# Should work
./publish/nethermind --JsonRpc.WebSocketsPort 8546

# Duplicate argument error
./publish/nethermind --JsonRpc.WebSocketsPort 8546 --JsonRpc.WebSocketsPort 8546

# Unrecognized argument error
./publish/nethermind --JsonRpc.WebsocketsPort 8546

return options;
}

private static void ValidateCommandLineFlags(string[] args)
Copy link
Member

Choose a reason for hiding this comment

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

If we are validating here I would also move GetDuplicateArguments and duplication validation under this one method.

src/Nethermind/Nethermind.Runner/Program.cs Outdated Show resolved Hide resolved
src/Nethermind/Nethermind.Runner/Program.cs Outdated Show resolved Hide resolved
src/Nethermind/Nethermind.Runner/Program.cs Outdated Show resolved Hide resolved
@wugalde19 wugalde19 force-pushed the feature/add-validation-and-log-for-invalid-parameters branch from 5d6fda4 to db39f9e Compare August 20, 2024 03:43
@wugalde19
Copy link
Contributor Author

@LukaszRozmej I've already addressed all your comments and updated the video to validate new changes
Feel free to review it again and let me know if you have more feedback
Thanks

Copy link
Member

@LukaszRozmej LukaszRozmej left a comment

Choose a reason for hiding this comment

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

Better design, but way to much allocations.

src/Nethermind/Nethermind.Runner/Program.cs Outdated Show resolved Hide resolved
src/Nethermind/Nethermind.Runner/Program.cs Show resolved Hide resolved
src/Nethermind/Nethermind.Runner/Program.cs Outdated Show resolved Hide resolved
src/Nethermind/Nethermind.Runner/Program.cs Outdated Show resolved Hide resolved
src/Nethermind/Nethermind.Runner/Program.cs Outdated Show resolved Hide resolved
@wugalde19
Copy link
Contributor Author

@LukaszRozmej Thanks for all the feedback provided
Definitely learning a lot and it is forcing me to be more thoughtful with the code
Ready for another round of reviews

Copy link
Member

@LukaszRozmej LukaszRozmej left a comment

Choose a reason for hiding this comment

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

Cool, IMO code now is quite good, would apply few final touches to make it perfect ;)

src/Nethermind/Nethermind.Runner/Program.cs Outdated Show resolved Hide resolved
src/Nethermind/Nethermind.Runner/Program.cs Outdated Show resolved Hide resolved
src/Nethermind/Nethermind.Runner/Program.cs Outdated Show resolved Hide resolved
src/Nethermind/Nethermind.Runner/Program.cs Outdated Show resolved Hide resolved
src/Nethermind/Nethermind.Runner/Program.cs Outdated Show resolved Hide resolved
src/Nethermind/Nethermind.Runner/Program.cs Outdated Show resolved Hide resolved
@wugalde19
Copy link
Contributor Author

@LukaszRozmej one step closer to a better implementation
You are great
Thanks for your patience

@wugalde19 wugalde19 force-pushed the feature/add-validation-and-log-for-invalid-parameters branch from 77c0688 to 7419151 Compare August 22, 2024 02:13
@LukaszRozmej
Copy link
Member

Congrats for persistence ;)

@wugalde19 wugalde19 force-pushed the feature/add-validation-and-log-for-invalid-parameters branch from 7419151 to aeb937d Compare August 23, 2024 03:48
Co-authored-by: Lukasz Rozmej <lukasz.rozmej@gmail.com>
@wugalde19
Copy link
Contributor Author

@LukaszRozmej Just applied changes suggested on last two comments

@LukaszRozmej LukaszRozmej merged commit be7feb6 into NethermindEth:master Aug 24, 2024
66 checks passed
@LukaszRozmej
Copy link
Member

@wugalde19 thank you for your contribution 🫡

@benaadams
Copy link
Member

Fails for?

 --JsonRpc.JwtSecretFile=C:/ethereum/jwt.hex

🤔

@wugalde19
Copy link
Contributor Author

My pleasure @LukaszRozmej

@benaadams
Copy link
Member

Failed due to unrecognized argument - [JsonRpc.JwtSecretFile=C:/ethereum/jwt.hex].
Run --help for a list of available options and commands.

@wugalde19
Copy link
Contributor Author

JsonRpc.JwtSecretFile=C:/ethereum/jwt.hex

@benaadams Please try again
@LukaszRozmej came out with a much better solution (here)
Those changes seemed to have fixed the issue you were having

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Logs] No log info abotu invalid parameter applied
4 participants