There are a lot of cases when developers encounter invariants that need to be held, they will turn to "defensive programming", vigorous testing, auditing, or just wishful thinking.
There's another way! Enforce it using types! You will sleep better at night, trust me.