Only log the error if there's actually an error.
Wraps mkdirsSync in a try/catch in case that fails.

This also pulls the code to remove a failed installation out into a separate function
rather than adding a third instance of the same code.