Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing settings are not validated #245

Closed
oeoeaio opened this issue Sep 5, 2022 · 0 comments · Fixed by #246
Closed

Missing settings are not validated #245

oeoeaio opened this issue Sep 5, 2022 · 0 comments · Fixed by #246

Comments

@oeoeaio
Copy link
Contributor

oeoeaio commented Sep 5, 2022

Describe the bug

When the Setting::Loader is unable to determine the value of a particular setting it silently fails (does not raise an InvalidSettingsError). The setting value is only evaluated at runtime when some downstream component attempts to access it, and the exception raise is a Dry::Types::ConstraintError which makes no reference to the name of the offending/missing setting making it very hard to debug.

To Reproduce

Declare a settings provider that inherits from the settings provider source:

App.register_provider(:db_config, from: :dry_system, source: :settings) do
  settings do
    setting(:db_host, constructor: Types::String.constrained(filled: true))
  end
end

Then don't set a DB_HOST var in the environment.

Expected behavior

I get an InvalidSettingsError when the settings are loaded. Something like:

Could not load settings. The following settings were invalid: (Dry::System::ProviderSources::Settings::InvalidSettingsError)
db_host: nil violates constraints (type?(String, nil) AND filled?(nil) failed)

My environment

  • Affects my production application: Not yet
  • Ruby version: reproduced on 2.7.5 and 3.1.2
  • OS: macOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant