It’s a simple way to avoid repeating mistakes.
You get this for free if you follow the highly recommended practice of test-driven development.
If your code base doesn’t have that kind of coverage, always be sure that there is a test to cover fault, bug, mistake, error and unexpected result that you encounter.
There’s nothing worse than having bugs come back later. When you repeat the same mistake twice, did you learn nothing the first time? Avoid this.