When os.Stat returns an error different from ErrNotExist, mkdirAllWithPermissions may panic with a nil pointer derefence due to insufficient error checking. Avoid the panic by bailing out, returning the error to the caller.