foundry-rs / foundry-rs/foundry
feat(forge): optional chain sections and skip flags in script config
- Dominant language
- Rust
- Stars
- 10.6k
- Forks
- 2.6k
- Avg merge
- 18h 20m
- Merged PRs (30d)
- 510
Description
### Component
Config
### Describe the feature you would like
Foundry’s current `Config` loader (used by `_loadConfig` and `_loadConfigAndForks`) attempts to parse every configured chain section in a TOML file and will error if a section is present but effectively empty or missing expected keys. This makes multi-chain workflows harder when some chains intentionally lack certain config values.
**Example config**:
```toml
[sepolia]
endpoint_url = "${SEPOLIA_RPC_URL}"
[anvil]
endpoint_url = "http://127.0.0.1:8545"
[anvil.bool]
use_mocks = true
[anvil.uint]
mock_decimals = 8
mock_initial_price = 2000e8
```
In this file:
sepolia does not define mocks — and that’s fine.
anvil does not define price_feed — also fine.
But Foundry currently will throw when trying to load or parse these mismatched sections as if all chains must have all keys present.
### Proposal
1. Skip Empty Chain Sections with Warning
Treat a chain section as optional:
If a top-level chain section has no keys, skip it with a detailed warning:
```pgsql
Warning: Skipped config section for chain `` — no values found.
```
2. Add a Skip Flag
Add a new loader option to make this behavior explicitly opt-in:
```toml
_skipEmptySections = true
```
This flag would be passed alongside _loadConfig or _loadConfigAndForks, e.g.:
```solidity
_loadConfig("./deployments.toml", true, ConfigOpts.skipEmptySections);
```
Or via a global config option at the top of the TOML:
```toml
[_config]
skip_empty_sections = true
```
3. Verbose Warnings for Missing Keys
When a chain section has some keys but is missing others seen in other chains, emit a verbose warning:
```pgsql
Warning: chain `sepolia` missing key `use_mocks`; only defined under `anvil`.
```
This helps developers see mismatches in multi-chain configs.
4. Key Lookup Behavior (Unchanged)
Only throw at runtime when a script explicitly calls config.get(...) for a missing key.
Missing keys do not cause load errors with the skip option enabled.
### Summary of Desired Behavior
| Behavior | With Skip Flag (`_skipEmptySections = true`) |
|----------|----------------------------------------------|
| Empty chain section | Skipped with a detailed warning (`no values found` for that chain) |
| Missing key under a chain | No load error; only errors if script explicitly calls `config.get(...)` |
| Cross-chain mismatches | Emit verbose warnings showing which keys are missing under which chains |
| Backwards compatibility | Default behavior unchanged; skip flag is opt-in |
This feature will significantly improve ergonomics for multi-chain workflows where not every chain has every config value defined.
### Additional context
As shown below, Patrick Collins (of Cyfrin) highlights the failure case when blank chain sections are present:
Contributor guide
Assessment
This issue has not been assessed yet.