David’s sin is discovered, and he suffers terrible consequences. However, God is still gracious because David has another son who will be the one to be the next king. Despite his horrible failure, God keeps his promise.
We’ve all messed up, but God will keep his promises to us. Our assurance comes from God’s faithfulness, not ours.