Reviewing the Silent Default That Hid the Missing Config

The loader fell back to a built-in value when the key was absent, so the service ran with the wrong setting for a week, and the startup log said the…

Share
Reviewing the Silent Default That Hid the Missing Config. Abstract code review illustration in orange and dark grey on debugly.dev

Start at the wrong and you miss it. Start at the incident and you miss how it arrived. The bug lived in the hand-off.

I have hit this enough times that I now check for it before I check for anything clever.

Strip the silent default down and one property makes it expensive: the fallback converts a configuration error into a running service with the wrong behaviour, so the failure is deferred from the startup, where it is cheap, to the production, where it is not.

The case was a service loading its config from the environment; the mechanics generalise to any loader that substitutes a default when a key is absent.

What the review saw

The review saw the loader, and the loader was the getenv with the default, and the default was the safe, and the safe was the no crash, and the no crash was the good, and the good was the pass, because the fallback is the defensive practice, and the practice was the review's criterion, and the criterion was met, and the met was the miss.

The review did not ask whether the default is ever correct in production, and the ask is the question, and the question is the usually no, and the no is the crash's preference, and the preference is the loud failure, and the loud failure is the cheap, and the cheap is the startup, and the startup is the fix, and the fix is the review's question that nobody asked.

The fallback is the right pattern for the optional setting, and the optional is the theme and the log level, and the two are the harmless, and the harmless is the fine, and the fine is the not the database URL, and the database URL is the required, and the required is the crash, and the crash is the discipline, because the setting's criticality determines the fallback's correctness.

Why the log lied

The log said the configuration loaded, and the loaded was the true, and the true was the misleading, because the loaded was the object's construction, and the construction was the defaults' inclusion, and the inclusion was the silent, and the silent was the missing key's invisibility, and the invisibility was the week, and the week was the incident's duration.

The log did not say which values came from the environment and which came from the defaults, and the not said was the diagnosis' absence, and the absence was the week, and the week was the search, and the search was the code, and the code was the fine, and the fine was the configuration, and the configuration was the typo, and the typo was the answer, and the answer is the reason the loader should report the source of every value.

This is the same silence as the strace output that showed the file was never opened, which is why the two fixes look alike.

The questions that catch it

Is this setting ever correct at its default in production? The answer is the usually no, and the no is the crash's requirement, and the requirement is the fix, and the fix is the required flag, and the flag is the discipline, and the question is the review's first.

What happens when the key is missing? The answer should be the startup failure, and the failure is the loud, and the loud is the cheap, and the cheap is the fix, and the fix is the raise, and the question is the review's second, because the silent default is the deferred incident.

Does the log distinguish the sourced value from the default? The answer should be the yes, and the yes is the diagnosis, and the diagnosis is the fast, and the fast is the fix, and the fix is the log line, and the question is the review's third.

Is the default the safe value or the convenient value? The safe is the restrictive, and the restrictive is the correct fallback, and the convenient is the permissive, and the permissive is the risk, and the risk is the fix's target, and the question is the review's fourth.

The fix

Made the required settings fail at startup. The loader raised on the missing key, and the raised was the crash, and the crash was the deploy's failure, and the failure was the loud, and the loud was the fix, and the fix was the required list, and the list was the discipline.

Kept the defaults only for the genuinely optional settings. The optional was the log level and the timeout's tuning, and the two were the harmless, and the harmless was the fallback's legitimacy, and the legitimacy was the fix, and the fix was the classification, and the classification was the discipline.

Logged every value's source at startup. The log was the key and the source and the not the secret, and the source was the environment or the default, and the default was the visible, and the visible was the diagnosis, and the diagnosis was the fix, and the fix was the one loop.

Validated the loaded config against the schema. The schema was the type and the range, and the range was the absurd value's rejection, and the rejection was the fix, and the fix was the validation, and the validation was the discipline, because the parsed string is the untyped until the schema says otherwise.

Added a test with the key absent. The test was the missing environment, and the missing was the startup's failure, and the failure was the assertion, and the assertion was the guard, and the guard was the prevention, and the prevention was the fix.

The rule

A configuration loader should fail at startup when a required setting is missing, and reserve defaults for settings that are genuinely optional and safe. Log the source of every value without logging secrets, validate against a schema, and test the absent-key case.

The service ran for a week with a default value because an environment variable name had a typo and the loader silently substituted its fallback, and the startup log reported that the configuration had loaded. That is the whole pattern, and it is the part worth remembering.


Published on debugly.dev by Rohit Bhadani | Founder of Krova Cloud