Foiling a Trap. If adventurers detect a trap before triggering it, they might be able to foil it one way or another depending on the nature of the trap.
GM Discretion. In most cases, a trap’s description is clear enough that you can adjudicate whether a character’s actions foil the trap. As with many situations, you shouldn’t allow die rolling to override clever play and good planning. Use your common sense, drawing on the trap’s description to determine what happens. No trap’s design can anticipate every possible action that the characters might attempt.
See DMG p.120 and XGtE p. 113 for more information.