That is a close call. Luckily the only damage done was a 50 dollar pair of pants, and some pride and ego.
There is a big thing about holstering your handgun without having to look at it. Or “speed holstering” after shooting. I have no idea why so many people are in such a hurry to get their handgun back into the holster. I can say without doubt the big flashy training videos from a few years ago contributed to this.
Keep your gun out until you are 100 sure the threat is over. Then take your time putting it back in the holster. If you have a jacket on or a shirt or anything that might hang up in it, Look first! Especially if your handgun doesn’t have a manual safety.