Just when you think you've seen it all, along comes Genesis 38 (link) to show you just how bad it can get out there. This supports why we read through the whole Bible, though: you need to see that these are the lives of people just like people today. Lives full of shattered hopes and broken promises, but redeemed by the grace of God.
What happens this time around? Judah, the brother who had the idea to sell Joseph and not kill him, moves away from his brothers. We have one brother, Joseph, on his way to Egypt. We have another brother, Judah, separating from the family.
The text does not give us a reason for Judah to move away from his brothers. Perhaps he feels guilt over Joseph; perhaps they pressured him to move away lest he slip up and confess his part of the crime; perhaps they want him away so that if the Midianites who bought Joseph come back, he'll be gone. We just don't know.
What we do know is this: the twelve sons of Jacob are now down to ten in the household. Judah's absence here is not a temporary one—we see him marry and raise his three sons. Two of which are not good. The text gives us that Er was evil so Yahweh took his life: Genesis 38:6. I think there's some importance to using God's covenant, personal name here rather just a reference to "God:" whatever was wrong in the heart and behavior of Er was not about a generic complaint. It had to do with dishonoring the covenant that Yahweh had made with Abraham, Isaac, and Jacob.
If that was not enough, Onan, Er's younger brother, is also struck down. By the same One, for the same reason. Onan was expected to marry Er's wife, Tamar, and protect and provide for her. Alongside that, their first child would have been counted as Er's offspring rather than Onan's offspring. That child would have received the firstborn's estate from Judah's inheritance—as it stands, Onan will get that estate along with his own.
So, Onan does not want Er to have a son in his name. Some assume that Onan's explicit sin of practicing a primitive birth control is why he was struck dead. I think it was more about the attitude and his unfaithfulness to the covenant and character of God. In no place does Scripture condemn preventative birth control, though we are to see God as the opener and closer of the womb, but that's another discussion.
Judah now sees a pattern: two sons married to Tamar. Two sons dead. He doesn't want to lose the third son, so he refrains from allowing Shelah, his third son, to marry her.
The blame is in the wrong place here. The fault in this case rests on three people, possibly four, and Tamar is not one of them. Er and Onan chose their own unfaithfulness, but does Judah not bear some responsibility? It seems that he has chosen to raise a family separate from the covenant people of God and now finds himself hammered by the consequences of that choice.
Not that being raised in the covenant family is a guarantee: Jacob and Esau have already shown us that fact. However, there's a gap between a guaranteed fail and a guaranteed win and in the gap are decisions that help or hurt your opportunities.
Those who do not even try to start off right are going to fight an uphill battle for years; those who do try are not guaranteed success but it is more likely.
There have been those raised to hate God who He finds and draws to Himself anyway. There have been those raised to love God who run from Him and hate Him.
What choice are you making? To move away from the people of God? True, sometimes God's people are hard to deal with, but are you really better off without them?
I'd say we're not. We need each other, even with our shortcomings and failures. Together, we can raise each other up to follow the Lord God better than each of us individually.