cloudflare / foundations

Cloudflare's Rust service foundations library.
https://blog.cloudflare.com/introducing-foundations-our-open-source-rust-service-foundation-library
BSD 3-Clause "New" or "Revised" License
1.25k stars 51 forks source link

ZTC-1545: Error during settings deserialization if YAML contains unused keys #49

Closed OmegaJak closed 2 months ago

OmegaJak commented 3 months ago

The goal is to help users of foundations catch possible configuration mistakes which, depending on the context, could have serious consequences. For example, if a config field is renamed, but the name is not changed in the deserialized YAML file, foundations will use the defaults for the renamed config value, which may differ substantially from the previous value. With this change, if the feature is enabled, foundations will return an error on deserializing the YAML file since it contains an unused key.

This takes a different approach from #43. This PR results in an error instead of a logged warning, making it much harder to ignore.

This adds a new option to the #[settings] macro, default_deny_unknown_fields, which defaults to true. When true, foundations will error on unknown fields. If set to false, it won't.