Sometimes Allah allows some situations to go worse and closes all the doors only to see what his slave will do now. Will he still be grateful to his Lord and endure with patience or will he turn back on his knees.
If Allah willed, he could have given an easy exit to Musa (as). He might have taught him some better route where he wouldn't get stuck, But Nay! Allah wanted to test his conviction, so he allowed the situation to go worse.
And when the slave shows that ultimate conviction and belief in Allah like Musa (as) showed when got caught by Pharaoh from behind and Ocean in front, he didn't lose hope in his Lord and said with full conviction, "No, My Lord is with me and He will guide me." It is that conviction which Allah wants to see and then Allah makes a way out even if it was to split the ocean, make the fire cool or split the moon into pieces, Allah will do it for his slave.
Allah will never fail you. You just need to show your conviction.