Skip to content

feat(cheatcodes): Revert ffi on non-zero exit code #11101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mutestt
Copy link

@mutestt mutestt commented Jul 25, 2025

Motivation

This PR addresses the // TODO: check exit code? in the ffi 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 on vm.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:

  • If an ffi command exits with a non-zero code, the cheatcode will now revert.
  • The revert message has been made more informative, including the command, the exit code, and the contents of stderr to simplify debugging.
  • For commands that exit successfully (code 0) but still write to stderr (e.g., for warnings), the output is now logged as a warn! instead of an error!.
  • A new unit test is added to verify that vm.ffi correctly reverts when a command returns a non-zero exit code.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant