A merciful providence just saved me in time from falling into the trap.
I was lucky enough to realize just in time that it was a trap.
I could not realize in time that there was a trap, and I fell right into it.