Have you ever found yourself walking down a long passageway only to meet a dead end sign? How about completing a form, tapping submit and only then finding out some fields were mandatory? If you’re a developer, how many times have you ended up with data in a weird state?
What do all of these have in common, other than being incredibly frustrating?
In all of these cases, someone decided to wait until the last minute to tell you something was unexpectedly wrong.
Don’t be that someone. The solution is simple. Fail early. Inform people of issues as soon as you can. Don’t let them waste time and effort to find out.
Put the sign on the entrance to the passageway. Mark mandatory fields. Throw an exception as soon as you encounter an invalid state.
Few things are more disappointing than finding out the light at the end of the tunnel is a train.