Seems like you had low lucidity or just got startled in the dream, causing you to wake up.

So you don't lose it next time, just try to stay calm and aware of what's going on. What I do to have higher lucidity, is I yell "increase lucidity!" That seems to help. Clapping once and listening to the noise also helps me and so does rubbing my hands together and telling myself "this is a dream". Try that