Solomon saw at the end of his life that everything he chased after was "chasing after the wind", in other words it was to his credit that he realized at the end of his life looking back he could see how silly he was, this is wisdom.
I know many people who do not admit they needed to learn anything. They are as foolish at the end of their lives believing they had a great life without mistakes and sins.
A wise person looks back and sees how much they failed and what they learned from it. A foolish man looks back and convinces themself he did everything right and would do it all over again.
Ecclesiastes 1:17
"So I set my mind to know wisdom and madness and folly; I learned that this, too, is a pursuit of the wind."
Ecclesiastes 2:11
"Yet when I considered all the works that my hands had accomplished and what I had toiled to achieve, I found everything to be futile, a pursuit of the wind; there was nothing to be gained under the sun."
Ecclesiastes 2:17
"So I hated life, because the work that is done under the sun was grievous to me. For everything is futile and a pursuit of the wind."
Ecclesiastes 2:26
"To the man who is pleasing in His sight, He gives wisdom and knowledge and joy, but to the sinner He assigns the task of gathering and accumulating that which he will hand over to one who pleases God. This too is futile and a pursuit of the wind."
Ecclesiastes 4:4
"I saw that all labor and success spring from a man's envy of his neighbor. This too is futile and a pursuit of the wind."
Ecclesiastes 4:16
"There is no limit to all the people who were before them. Yet the successor will not be celebrated by those who come even later. This too is futile and a pursuit of the wind."
Ecclesiastes 6:9
"Better what the eye can see than the wandering of desire. This too is futile and a pursuit of the wind."
It is the wise person who can look back and admit their failures and glory in the lessons that God brought. Our failures cannot teach us if we cannot admit they were failures.