Repository navigation
feat(config): aggregate all resolution problems into one error (#222) - #606
Conversation
resolve_config used to fail fast on the first problem, forcing an operator with N config mistakes through N edit/run cycles. It now threads a ConfigErrorBag through every section so a single pass reports every problem as a bulleted list. - New config::errors module: ConfigErrorBag (check/try_with/ has_field/into_result) plus one_section shim helper. - Each fallible section gains a *_into(&mut bag) worker; the public resolve_payment/resolve_observability/resolve_security keep their anyhow::Result signatures (runtime::reload depends on them) via thin one_section shims, as do the test-only private shims. - Required-but-invalid fields get placeholders so later independent checks still run; cascade-prone dependents are guarded (rpc_url scheme, slash_judge zero-addr, region/subscribe_global, keystore-on-placeholder-data_dir). - load_file_config stays fail-fast (cannot validate a FileConfig that never parsed). - Original message text is preserved verbatim under a dotted field label, so the existing substring-based test suite is unchanged. - Adds multi-error coverage: a resolve_config unit test and a config validate integration test. Co-Authored-By: Claude Opus 4.7 <[email protected]>
Coverage reportTotal: 89.90% (was 89.66%, ▲ +0.24%) — 16587/18450 lines
History
|
There was a problem hiding this comment.
Code Review
This pull request introduces a structured error accumulation mechanism for configuration validation to address issue #222. By implementing a ConfigErrorBag utility, the system now collects and reports all validation errors across various configuration sections—such as identity, blockchain, and cache—in a single pass, rather than failing on the first error encountered. The resolve_config function and its sub-resolvers have been refactored to support this aggregated reporting, and new tests ensure that multiple errors are correctly identified and reported without misleading cascades. I have no feedback to provide.
There was a problem hiding this comment.
Pull request overview
This PR improves operator UX during configuration resolution by accumulating all validation/resolution problems into a single aggregated error (instead of failing fast on the first issue), addressing #222.
Changes:
- Introduces
ConfigErrorBagto collect validation errors and emit one combined “configuration has N problem(s)” error. - Refactors config resolution to thread a shared error bag through section resolvers (
*_into) and cross-section validations. - Adds unit/integration tests to ensure multiple independent errors are reported in one run.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/common/src/config/mod.rs | Refactors resolution flow to accumulate errors across sections and adds a unit test for multi-error aggregation. |
| crates/common/src/config/errors.rs | Adds the new ConfigErrorBag + helpers (check, try_with, into_result, one_section) and unit tests. |
| crates/cli/tests/config_validate.rs | Adds an integration test asserting config validate emits multiple problems at once. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if !cond { | ||
| self.push(field, message); |
There was a problem hiding this comment.
Fixed in 21c1b68: added a lazy check_with(field, cond, || format!(...)) and converted the 12 dynamic-message call sites to it, so formatting/allocation happens only on failure (matching the original anyhow::ensure! behaviour). Static-message sites keep check.
| let n = self.problems.len(); | ||
| let bullets = self | ||
| .problems | ||
| .iter() | ||
| .map(|p| format!(" - {}: {}", p.field, p.message)) | ||
| .collect::<Vec<_>>() | ||
| .join("\n"); | ||
| Err(anyhow::anyhow!( | ||
| "configuration has {n} problem(s):\n{bullets}" | ||
| )) | ||
| } |
There was a problem hiding this comment.
Fixed in 21c1b68: into_result now indents continuation lines (replace('\n', "\n ")) so a multi-line message stays under its bullet. Added a unit test covering it.
| .transpose()? | ||
| .map(|v| { | ||
| v.iter() | ||
| .filter_map(|s| bag.try_with("gossip.allowlist", parse_node_id_hex(s))) |
There was a problem hiding this comment.
Fixed in 21c1b68: allowlist entries are now recorded under gossip.allowlist[<idx>] (via .enumerate()), matching the cache.origins[<idx>] pattern. Verified manually — two bad entries now report as distinct gossip.allowlist[0] / gossip.allowlist[1] bullets.
- ConfigErrorBag: add lazy `check_with` (closure-built message) so the 12 dynamic-message call sites format only on failure, restoring the `anyhow::ensure!` semantics this PR replaced; static-message sites keep `check`. - into_result: indent continuation lines of multi-line messages so a wrapped message still reads as one bullet. - resolve_gossip_into: index allowlist error labels (`gossip.allowlist[idx]`) for actionable, per-entry reporting, matching the existing `cache.origins[idx]` pattern. - Adds errors.rs unit tests for check_with laziness and multi-line bullet indentation. Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements a structured configuration validation error accumulator, ConfigErrorBag, to address issue #222. Instead of failing fast on the first configuration error, the system now collects all validation issues across different sections (identity, blockchain, cache, payment, etc.) and reports them collectively. The changes include refactoring existing resolver functions into *_into variants that accept the error bag, adding logic to suppress misleading cascade errors, and introducing comprehensive unit and integration tests to verify the aggregated error reporting. I have no feedback to provide as there were no review comments.
) Addresses the multi-agent review of PR #606. No production control-flow change (label constants are value-identical strings). Tests (pr-test-analyzer Gaps A/B/C): - resolve_cache_origins_accumulates_every_bad_entry: two malformed origins (idx 0, 2) both reported by index, valid idx 1 absent. - Strengthened resolve_gossip allowlist test → accumulates every invalid entry by index (was the stale pre-#222 fail-fast premise). - resolve_config_missing_rpc_url_emits_no_parse_cascade: missing rpc_url is the sole problem, no "is not a valid URL" cascade. - resolve_config_malformed_slash_judge_emits_no_zero_address_cascade. - resolve_config_aggregates_cross_and_intra_section_problems: exact 4-count across cross + intra-section with region cascade suppressed. - config_validate: lock the fail-fast boundary (file-load errors must not be wrapped in the aggregate header). Hardening (type-design-analyzer #1 + silent-failure-hunter Finding 3): - IDENTITY_REGION / IDENTITY_DATA_DIR consts used at both the producing and has_field guard sites so a rename can't silently disable cascade suppression. Comments (comment-analyzer): qualified the "verbatim" claims (multi-line messages get indented continuations), corrected the resolve_gossip doc to the drop-and-record-by-index behaviour, and tightened the keystore guard comment to state the defaulted-keystore skip is deliberate. Co-Authored-By: Claude Opus 4.7 <[email protected]>
#606) Self-audit cleanup of comment cruft and a weakly-tested invariant introduced earlier in this PR. No production behaviour change. errors.rs: - Drop migration-narrative phrasings ("used to fail fast", "matches what ? produced before", "all current ones") and #222 issue references — replace with present-tense behaviour descriptions. - Tighten one_section doc: drop the per-function enumeration that would rot, name runtime::reload as the navigation target. - Remove the #[cfg(test)]-only is_empty method (no production consumer; into_result().is_ok() encodes the same predicate, and has_field covers the targeted mid-flight peek). - Strengthen check_records_only_on_false_and_returns_cond: assert exact "1 problem(s):" count and the absence of the true-branch message, so a regression that pushed regardless of cond fails. mod.rs: - Drop #222 references from resolve_config and test docs. - Per-pair distinct labels in validate_port_layout_into ("network.bind_port vs observability.metrics_port", etc.) so an operator who set all three equal sees three distinguishable bullets instead of two collisions under one key. - Expand the data_dir / placeholder / has_field rationale comments to spell out why the placeholder never escapes resolve_config. config_validate.rs: - Drop the "(issue #222 boundary)" phrasing; describe the fail-fast/aggregate split present-tense. Co-Authored-By: Claude Opus 4.7 <[email protected]>
Summary
Closes #222.
resolve_configused to fail fast on the first problem, forcing an operator with N config mistakes through N edit/run cycles. It now threads aConfigErrorBagthrough every section so a single pass reports every problem as one actionable bulleted list.Design
crates/common/src/config/errors.rs(new) —ConfigErrorBag:check(static-messageensure!replacement),check_with(lazy|| format!(...)for dynamic messages, restoringensure!'s allocate-on-failure behaviour),try_with(replaces?/.context()),has_field(cascade-suppression guards; exact-string match, not prefix),into_result(one bulletedanyhow::Error, with continuation lines of multi-line messages indented under their bullet), plus theone_sectionshim helper.IDENTITY_REGION/IDENTITY_DATA_DIRpub(crate) constlabels make the only two cascade-guarded field strings refactor-safe (a rename can't silently disable suppression).crates/common/src/config/mod.rs— every fallible section gains a*_into(&mut bag)worker;resolve_configruns all 8 sections + both cross-section checks against one shared bag, thenbag.into_result()?. Publicresolve_payment/resolve_observability/resolve_security(andparse_pinned_hashes) keep theiranyhow::Resultsignatures —runtime::reloadcalls them — via thinone_sectionshims; the test-only private shims (resolve_blockchain,resolve_cache,resolve_gossip,resolve_identity,validate_port_layout,ensure_region_when_publishing_global) are gated#[cfg(test)].slash_judgezero-address (skipped on parse failure), region ↔subscribe_global(skipped when region present-but-invalid viahas_field(IDENTITY_REGION)), defaulted keystore existence (skipped on placeholderdata_dir— an explicitly-set keystore path is always checked). Placeholders never escaperesolve_config:bag.into_result()?short-circuits before the materializedResolvedConfigis returned.load_file_configstays fail-fast — file-not-found / TOML-parse / env-var-expansion errors cannot be accumulated against aFileConfigthat never parsed; integration test asserts they are not wrapped in the aggregate header.network.bind_port vs observability.metrics_port, etc.) so an operator who set all three equal sees three distinguishable bullets, not two collisions under one key.Review feedback addressed
check_with; the 12 dynamic-message call sites format only on failure.into_resultindents continuation lines (with a unit test).gossip.allowlist[<idx>]via.enumerate(), matching thecache.origins[<idx>]pattern.rpc_urlemits no parse cascade; malformedslash_judgeemits no zero-address cascade), a combined cross+intra exact-count test, and aconfig validatefail-fast boundary assertion. Strengthened thecheck_records_only_on_false_and_returns_condunit test to assert exact count + absence of the unwanted message.IDENTITY_REGION/IDENTITY_DATA_DIRconsts at bothpushandhas_fieldsites.validate_port_layout_into.resolve_gossipdoc to the drop-and-record-by-index behaviour; tightened the keystore-guard comment.#222references from production code/comments (they belong in this PR description, not the merged source); dropped the#[cfg(test)]-onlyis_emptymethod (no production consumer;into_result().is_ok()encodes the same predicate); simplified theone_sectiondoc to nameruntime::reloadas the navigation target without enumerating specific shim functions.Test plan
cargo nextest run -p decdn-common -p decdn-cli -p decdn-node— all green (1 skipped:bundle_create::determinism_…, a pre-existing macOS case-insensitive-FS issue confirmed identical on cleanmain, unrelated).cargo clippy --workspace --all-targets,cargo fmt --check,cargo doc -D warnings,cargo deny— clean (verified via pre-commit hooks on every push).decdn config validateemits all 6 at once, exit 1, with the region→subscribe_globalcascade suppressed andgossip.allowlist[0]/gossip.allowlist[1]as distinct indexed bullets.Commits
ea53bc3— feat:ConfigErrorBag+*_intoworkers +one_sectionshims21c1b68— refactor: lazycheck_with, multi-line indentation, indexed allowlist labels3507615— test: close review gaps,IDENTITY_*label consts, comment accuracy776ff73— refactor: drop#222/migration-narrative cruft, drop unusedis_empty, per-pair port-collision labels, strengthen weakened test🤖 Generated with Claude Code