Some code is small enough that it's feasible to prove that the code is correct, assuming that the underlying hardware, libraries, operating system, etc.. don't fail. For example, in most languages you really don't need to put error-checking in code as trivial as this pseudo-code:
boolean isGreater(int a, int b)
{return (a>b);}
Sometimes, particularly when running in "small/tight" or real-time environments or when security is more important than debuggability, you may want a failure to be nothing more than something basic like "return -1" or "turn on aralm and halt the CPU" or even "flush caches, destoy security keys, and power off."
But you are corrent, in most cases good souce code will have good, clear, easy-understand debugging code.