feat(cheatcodes): Revert ffi on non-zero exit code #11101
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
This PR addresses the
// TODO: check exit code?
in theffi
cheatcode implementation.The current behavior of
vm.ffi
can be unintuitive and lead to silently failing tests. It ignores the exit code of the executed command, meaning a script that fails (returns a non-zero exit code) does not cause the cheatcode to revert or the test to fail. This makes it difficult to rely onvm.ffi
for scripting that depends on the success of external commands.Solution
This change modifies the
ffi
cheatcode to check the command's exit code and provide more robust error handling:ffi
command exits with a non-zero code, the cheatcode will now revert.stderr
to simplify debugging.stderr
(e.g., for warnings), the output is now logged as awarn!
instead of anerror!
.vm.ffi
correctly reverts when a command returns a non-zero exit code.PR Checklist
Note on Breaking Change: This is marked as a breaking change because existing tests that rely on
vm.ffi
not reverting on a failed command will now start to fail. This is the desired and more correct behavior.