Wrote a peice of code that does something uniquc in my point of view.
After that i was so excited that i published it. Only to find out that it
contain a bug. By the way the bug was very defficul to spot.
and by solving the bug i reworte all the software again.
so my question is was i wrong in publishing the code (software)?
and when it is even good to publish a code (software) as a finished product.
i have seen some sotfwares with realy bad bug but it is still out there and people are
using it.
so as developers what do we do?

Do what Microsoft does, create a new and improved version.

was i wrong in publishing the code (software)?

No. If you think it's ready and well-tested, you should.

when it is even good to publish a code (software) as a finished product.

I've never seen a (completely) finished product.

so as developers what do we do?

Create the next version.

Java has been around for about 20 years and they still correct their bugs about every week.