Invental/Review lessons/Code that silently does the wrong thing

Code that silently does the wrong thing

Scope a kill switch to the feature it guards

A kill switch added to a shared validation path must be scoped to the feature it guards, or flipping it silently disables checks for unrelated data that shares the same code.

01 · Before and afterThe pattern

Scope the bypass by object type, and read flags positively.

Go
// before: one switch disables "required" for every field type
if enforced() && isRequired(f) && isEmpty(v) { return errRequired(f) }

// after: only project fields follow the switch; others are always enforced
enforce := f.ObjectType != ObjectTypeProject || flags.ProjectFieldsRequired
if enforce && isRequired(f) && isEmpty(v) { return errRequired(f) }

02 · Run it on your appThe check

When you add an “off switch” to a shared validator, is there a test proving that other record types are still validated with the switch on?

If the honest answer is no or not sure, this is worth a look before it reaches production.

Want this checked on your code?

Tell us what you are building and what worries you. We match a senior reviewer to your code and confirm scope before anything starts.

— Get in touch
hi@invental.co ↗
— Or
— What to include

A link or short description of the code or system, what you want checked, your stack, and when you need the answer. No repository access is needed until scope is agreed.

— Or leave a note
We reply within one business day.