In this Sunday’s Gospel reading Jesus reminds his disciples;
I have much more to tell you, but you cannot bear it now. But when he comes, the Spirit of truth, he will guide you to all truth. He will not speak on his own, but he will speak what he hears, and will declare to you the things that are coming.
Jesus has promised that he will guide the Church into all truth. Although individual members of the Church may reveal their sinfulness or even at time cause scandal, the teaching office of the Church is protected by a charism of truth in the area of faith and morals.
The Catechism refers to this point quoting from Second Vatican Council (LG 25);
Divine assistance is also given to the successors of the apostles, teaching in communion with the successor of Peter, and, in a particular way, to the bishop of Rome, pastor of the whole Church, when, without arriving at an infallible definition and without pronouncing in a "definitive manner," they propose in the exercise of the ordinary Magisterium a teaching that leads to better understanding of Revelation in matters of faith and morals. To this ordinary teaching the faithful "are to adhere to it with religious assent" [religioso animi obsequio adhaerere debent ]422 which, though distinct from the assent of faith, is nonetheless an extension of it. CCC 892
Holy Mother Church, on her pilgrimage through the ages, has been infallibly guided by divine assistance in her magisterial teachings. This assistance is the work of the Holy Spirit.