Life just never worked out the way Joseph had planned. I'm sure he imagined how wonderful marriage to Mary would be. The pain and disappointment he felt when Mary told him she was pregnant must have been great. Before he was told in a dream that the situation was from God, he showed great love toward Mary. He wanted to quietly take her away, to save her from disgrace. The marriage was not working out the way he had planned but God was in it.
How did he feel when arriving in Bethlehem, after a long and exhausting trip, to find there was no place for them at an inn? He could not find suitable accommodations for his wife, who was so close to giving birth. How did he feel when the child he would raise, was born in a stable with the livestock? Did he feel like a failure, an insufficient provider? This was not as he had imagined, but God was in it.
I wonder if Joseph liked living in Egypt? In one instance he had plans of returning to Nazareth with his expanded family. He probably was looking forward to the joy of being reunited with friends and loved ones. Introducing them to the new arrival. In the next instance the family are fleeing for their lives to Egypt. Egypt instead of Nazareth, but God was in it.
Sometimes life doesn't seem to be working out. Maybe, just maybe, God is in it.