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

feat: Extend support for env-based configuration #631

Closed
wants to merge 2 commits into from

Conversation

pierre-l
Copy link
Contributor

BREAKING CHANGE: Config::from_env now returns an eyre::Result instead of panicking on site.

The primary motivation is #630 , but I also wanted more explicit messages when running Beerus without specifying the STARKNET_RPC and ETH_EXECUTION_RPC keys.

@pierre-l pierre-l marked this pull request as ready for review April 17, 2024 09:09
crates/core/src/config.rs Outdated Show resolved Hide resolved
BREAKING CHANGE: `Config::from_env` now returns an `eyre::Result`
Copy link
Collaborator

@sergey-melnychuk sergey-melnychuk left a comment

Choose a reason for hiding this comment

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

Some unit-tests would be a nice addition to solidify configuration invariants

crates/core/src/config.rs Outdated Show resolved Hide resolved
crates/core/src/config.rs Outdated Show resolved Hide resolved
crates/core/src/config.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@sergey-melnychuk sergey-melnychuk left a comment

Choose a reason for hiding this comment

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

Just to be clear: this PR looks acceptable and I assume works right but needs unit-tests coverage for configuration factory code. To achieve that decoupling from std::env::var seems to be necessary.

@pierre-l
Copy link
Contributor Author

@sergey-melnychuk @LKozlowski I added a second commit for the unit tests
(also thanks for the issue & resolved threads)

};

Ok(Self {
network: Network::from_str(&get("NETWORK").unwrap_or_default())
Copy link
Collaborator

Choose a reason for hiding this comment

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

if the provided network is invalid, then mainnet is used as a default which might not be always desired behavior; I think an error must be returned when provided network is invalid - with respective test case.

eth_execution_rpc: require("ETH_EXECUTION_RPC")?,
starknet_rpc: require("STARKNET_RPC")?,
data_dir: PathBuf::from(get("DATA_DIR").unwrap_or_default()),
poll_secs: u64::from_str(&get("POLL_SECS").unwrap_or_default())
Copy link
Collaborator

@sergey-melnychuk sergey-melnychuk Apr 19, 2024

Choose a reason for hiding this comment

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

if provided poll seconds value is invalid also the default is used - probably safer to return an error; will also require one more test case for that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the original behavior. It's out of scope of this PR. It doesn't help with with my original task. It would be another breaking change.

@pierre-l
Copy link
Contributor Author

I really wish is was possible to fix one little thing without having to fix everything that's around, significantly extending the scope of an initially trivial PR, and bringing multiple breaking changes in the process.
I'm closing this PR.

#630 will use config files.

@sergey-melnychuk
Copy link
Collaborator

I really wish is was possible to fix one little thing without having to fix everything that's around, significantly extending the scope of an initially trivial PR, and bringing multiple breaking changes in the process. I'm closing this PR.

I guess I am sometimes getting carried away with "ownership mentality" over the project and the boy scout rule ("Leave your code better than you found it.")

Yet I personally believe there is still value to improve the code at every opportunity provided. If the original behavior allows invalid configuration parameters to be propagated through the system, I don't see why we should stick to it and not improve it in place (with just a few lines of code btw). If some test cases are missing for the code being changed, why not fill this gap for the team and the project to benefit?

No one forces us to stick to the "original behavior". No one forces us not to to extend the scope of the PR slightly to improve code quality and test coverage. But what I believe what we as a team force each other to do (and keep each other accountable for doing it) is to stick to the highest code quality standards possible every time, every LoC and every PR.

#630 will use config files.

If I'm being completely honest, I don't see why it might be a problem. https://github.com/eigerco/beerus/pull/630/files#r1574811607

@sergey-melnychuk sergey-melnychuk deleted the config-from-env branch May 29, 2024 20:33
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.

3 participants