Awesome Reviewers

Reviewer · Configurations

Config design and validation

Treat new or changed configuration options (daemon config fields, feature flags, env vars) as long-lived API surface: design them defensively and validate them thoroughly.

Instruction

Treat new or changed configuration options (daemon config fields, feature flags, env vars) as long-lived API surface: design them defensively and validate them thoroughly.

  1. Validate the full value space, not just the happy path: check interdependent settings together (e.g. if two related options must be set as a pair, reject the case where both are unset, not only when they disagree), and enforce sane bounds on values (e.g. a configurable timeout must be validated as > 0, since a value that merely “parses” can still be meaningless at runtime).

  2. When a new opt-out/override flag relaxes a safety check, scope it narrowly so it can’t silently disable protection for settings the user never touched. Require the related setting to be explicitly configured before honoring the opt-out, e.g.:
    // trust-default-address-pools opts out of the safety heuristics, so it
    // must not apply to the built-in default pools.
    if config.TrustDefaultAddressPools && len(config.DefaultAddressPools.Value()) == 0 {
     return errors.Errorf("trust-default-address-pools requires default-address-pools to be configured")
    }
    

    Also avoid loaded/ambiguous terms such as “trust” or “safe” in flag names and error messages, since their meaning isn’t self-evident.

  3. Don’t encode policy as a bare bool when it is likely to need richer semantics later; prefer an enum/string or a small struct (optionally with a discriminator/id field) so the option can evolve without a breaking change — e.g. requirement: "required" | "optional" instead of Enabled bool, and a de-duplicated slice/struct instead of a bare map[string]... when ordering or duplicate detection matters.

  4. Reuse existing constants and build tags instead of introducing parallel ones: match against already-defined mode/config constants (cfg["mode"] == ModeNonBlocking) rather than hardcoded string literals, and reuse an existing build tag (e.g. _unix) instead of duplicating platform-specific config files/options.

Applying these checks consistently prevents silent no-ops (e.g. an unvalidated zero timeout), incomplete validation (missing the “both unset” case), and configuration schemas that need breaking changes shortly after being introduced.