ulo
ulo
Documentation

Start here

Coming from NestJSNestJS topics, mapped

The model

Protocols

Integrations

ConfigurationSourcesValidation and problemsSecrets

Operating

Reference

Configuration

Validation and problems

What wire() reports for a bad configuration, how to add your own checks, and how unread keys are handled.

Every problem in the configuration is reported by wire(), in one report, before any module connects. A configuration with four wrong values reports four problems rather than stopping at the first.

What a report holds

Each problem names the field's path, the origin that supplied the value, and what was expected. The report's Display is a header with the count, then one line per problem:

<header> (4 problems)
http.port at <file>:4:8: <what was expected>
database.pool_size at <file>:7:13: <what was expected>
...

A source that fails, a file that does not parse for instance, contributes its own problems, and the keys it should have supplied are then reported missing. A failing source yields one ValueFailed entry for each module that read a section from it.

The structured list stays reachable. examples/33-config reads it back from the wiring error:

examples/33-config/tests/layers.rs
use ulo_config::ConfigError;

let problems = failed[0].downcast_ref::<ConfigError>().expect("the structured list stays reachable").problems();

Each Problem has path(), origin() and message(). An Origin is one of File { path, line, column }, Variable { name }, Explicit { key } or Default. A .env file reports a line and no column.

What is collected

The top-level keys of the type being read are sections, and each is read on its own. Every problem in every section is reported: missing fields, wrong types and out-of-range numbers. Within a section, the report holds the problems found up to the first error raised by a leaf type's own Deserialize, such as an IpAddr or a Url refusing a string, because serde stops there and nothing outside serde can resume it.

Three consequences follow from that limit:

  • A section written under a #[serde(alias)] key that ends on a leaf-type error is also reported missing required field under the field's own name.
  • A missing section whose type refuses a placeholder hides the missing fields declared after it. With database and cache both missing, one is reported.
  • The fields of a #[serde(flatten)] struct after a failed section are not reported in the same load.

Under #[serde(flatten)], serde gives an error in buffered content no key. Such a problem is reported at the path and origin of the struct holding the flatten, and its line ends with (inside a flattened section).

At most 2048 sections and missing fields are reported together. A longer report ends with a line reading the report stopped after N problems; fix these and read again.

Your own checks

ConfigModule::validate takes a closure that runs on the loaded value. Each p.at(path, message) joins the report:

crates/ulo-config/tests/layers.rs
use ulo_config::{ConfigModule, Problems};

m.import(ConfigModule::<Whole>::new(&self.0).validate(|whole: &Whole, p: &mut Problems| {
    if whole.http.port == 1 {
        p.at("http.port", "must not be a privileged port");
    }
    if whole.database.pool == 0 {
        p.at("database.pool", "must not be zero");
    }
}));

The hook runs only when the value loaded. Source failures, value problems and the hook's findings arrive in one entry.

Keys nothing reads

At connect, ConfigModule logs at warn every key that a source supplied and no section read, with its origin. .deny_unread() refuses connect instead:

examples/33-config/src/lib.rs
m.import(ConfigModule::<AppConfig>::new(&self.config).deny_unread());

A misspelled APP_HTTP__PROT=5000 in .env is then a startup failure naming the key and the file and line that supplied it, where otherwise the key would be ignored and the default used.

Unread keys cannot be a wire() refusal. The core runs no hook after every module has registered, and a module loaded lazily may read a key later.

Sources

The five sources of a Config, how names map to paths, and the file formats.

Secrets

How a value wrapped in Secret stays out of configuration reports, Debug output and logs.

On this page

What a report holdsWhat is collectedYour own checksKeys nothing reads