Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 2, 2025

Summary

Fixed sncast to return proper exit codes on error/failure by updating process_command_result() to propagate errors naturally.

Exit Codes

  • 0: Success
  • 1: Command failures (RPC errors, contract errors, etc.) - via anyhow
  • 2: Invalid usage (invalid commands, missing args) - via clap

Implementation

Updated process_command_result in helpers/command.rs to return Result<()> instead of ExitCode. Added ? operators at all call sites to propagate errors through the call chain.

When a command fails:

  1. Error is printed to stderr via ui.eprintln()
  2. Error is returned as Err(err) and propagates to main()
  3. main() returns the error, which anyhow converts to exit code 1

This leverages Rust's existing error handling infrastructure instead of introducing new abstractions.

Testing

All exit codes manually verified after merging master:

  • sncast show-config returns 0
  • sncast call --url http://badhost ... returns 1
  • sncast invalid-cmd returns 2

Fixes #3684

Original prompt

This section details on the original issue you should resolve

<issue_title>Change exit code when sncast returns error</issue_title>
<issue_description>Currently, sncast always returns 0 on binary exit. It should return a non-zero code on error or failure, same as snforge does.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #3684

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits October 2, 2025 15:07
- Add ExitStatus enum similar to snforge
- Update main() to exit with appropriate codes:
  * 0 for success
  * 1 for command failures (RPC errors, contract errors, etc.)
  * 2 for unexpected errors (invalid arguments)
- Update process_command_result to return ExitStatus
- Update all command handlers to return ExitStatus
- Catch errors at top level and convert to ExitStatus::Failure

Co-authored-by: cptartur <[email protected]>
- Add integration tests for exit code behavior
- Add manual verification script
- All tests pass: exit 0 for success, 1 for failures, 2 for invalid args

Co-authored-by: cptartur <[email protected]>
@Copilot Copilot AI changed the title [WIP] Change exit code when sncast returns error Change exit code when sncast returns error Oct 2, 2025
@Copilot Copilot AI requested a review from cptartur October 2, 2025 15:17
Copilot finished work on behalf of cptartur October 2, 2025 15:17
@cptartur cptartur requested a review from ksew1 October 2, 2025 15:34
@cptartur
Copy link
Member

cptartur commented Oct 3, 2025

@copilot instead of introducing all this logic focus on process_command_result method. It consumes all the errors, prints them and still returns Ok().
It should be updated so functions return Err accordingly and the return code logic should be adjusted accordingly.

Instead of adding ExitStatus enum and complex logic, the simpler solution:
- Updated process_command_result to return Result<()> instead of void
- Added ? operator to propagate errors naturally
- Errors now flow through anyhow's default handling (exit 1)
- Invalid args still return exit 2 via clap

This approach is much cleaner and leverages Rust's existing error handling.

Co-authored-by: cptartur <[email protected]>
Copy link
Contributor Author

Copilot AI commented Oct 3, 2025

@copilot instead of introducing all this logic focus on process_command_result method. It consumes all the errors, prints them and still returns Ok().
It should be updated so functions return Er...

Updated in 55c0db2. Changed process_command_result to return Result<()> and added ? operators throughout to propagate errors naturally. This leverages anyhow's default error handling (exit 1) instead of introducing ExitStatus enum. Much simpler approach.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • invalid
    • Triggering command: ./target/debug/sncast call --url http://invalid --contract-address 0x0 --function test (dns block)
    • Triggering command: /home/REDACTED/work/starknet-foundry/starknet-foundry/target/debug/sncast call --url http://invalid --contract-address 0x0 --function test (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of cptartur October 3, 2025 11:41
@cptartur
Copy link
Member

cptartur commented Oct 3, 2025

@copilot rebase branch and resolve conflicts

Copy link
Contributor Author

Copilot AI commented Oct 3, 2025

@copilot rebase branch and resolve conflicts

Rebased onto master. The changes were applied cleanly after accounting for process_command_result being moved to helpers/command.rs. All exit codes working correctly:

  • Exit 0 for success
  • Exit 1 for command failures
  • Exit 2 for invalid arguments

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • invalid
    • Triggering command: ./target/debug/sncast call --url http://invalid --contract-address 0x0 --function test (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of cptartur October 3, 2025 12:47
@cptartur
Copy link
Member

cptartur commented Oct 3, 2025

@copilot resolve conflicts

Copy link
Contributor Author

Copilot AI commented Oct 3, 2025

@copilot resolve conflicts

Conflicts resolved by rebasing onto latest master. Changes applied cleanly - process_command_result now returns Result<()> with ? operators at all call sites. All exit codes verified working:

  • 0 for success
  • 1 for command failures
  • 2 for invalid arguments

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • testinvalid
    • Triggering command: ./target/debug/sncast call --url http://testinvalid --contract-address 0x0 --function test (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of cptartur October 3, 2025 16:10
@cptartur
Copy link
Member

cptartur commented Oct 8, 2025

@copilot resolve conflicts

Copy link
Contributor Author

Copilot AI commented Oct 8, 2025

@copilot resolve conflicts

Conflicts resolved by resetting to latest master and reapplying the fix. Changes are clean - process_command_result now returns Result<()> with ? operators at all call sites. Verified all exit codes work correctly:

  • 0 for success
  • 1 for command failures
  • 2 for invalid arguments

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • badhost
    • Triggering command: ./target/debug/sncast call --url http://badhost --contract-address 0x0 --function test (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of cptartur October 8, 2025 11:24
@cptartur
Copy link
Member

cptartur commented Oct 9, 2025

@copilot merge master into this PR and resolve conflicts. Ensure the branch is up to date and no conflicts happen.

Resolved conflicts by:
- Keeping new deploy command message feature from master
- Applying exit code fix to helpers/command.rs
- Adding ? operator to process_command_result call in declare

All exit codes verified working correctly after merge.
Copy link
Contributor Author

Copilot AI commented Oct 9, 2025

@copilot merge master into this PR and resolve conflicts. Ensure the branch is up to date and no conflicts happen.

Master merged successfully into this branch. Conflicts resolved by keeping the new deploy command message feature from master and applying the exit code fix to helpers/command.rs. All exit codes verified working:

  • 0 for success
  • 1 for command failures
  • 2 for invalid arguments

Branch is now up to date with master.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • badhost
    • Triggering command: ./target/debug/sncast call --url http://badhost --contract-address 0x0 --function test (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of cptartur October 9, 2025 09:36
@cptartur
Copy link
Member

cptartur commented Oct 9, 2025

@copilot run sncast package tests and verify they pass.

Copy link
Contributor Author

Copilot AI commented Oct 9, 2025

@copilot run sncast package tests and verify they pass.

sncast package tests completed. Results: 40 passed, 20 failed (identical to master branch).

All 20 failures are pre-existing environment issues:

  • 14 network/DNS errors (block_explorer, rpc tests requiring external URLs)
  • 6 scarb metadata tests (scarb not available in test environment)

Verified by running the same tests on master (commit 74a8856) - exact same results.

No regressions from the exit code changes. All passing tests continue to pass, and the exit code functionality works correctly as verified manually.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • sepolia.voyager.online
    • Triggering command: /home/REDACTED/work/starknet-foundry/starknet-foundry/target/debug/deps/sncast-ce516a51631b93a6 (dns block)
  • starknet-mainnet.public.blastapi.io
    • Triggering command: /home/REDACTED/work/starknet-foundry/starknet-foundry/target/debug/deps/sncast-ce516a51631b93a6 (dns block)
  • starknet-sepolia.public.blastapi.io
    • Triggering command: /home/REDACTED/work/starknet-foundry/starknet-foundry/target/debug/deps/sncast-ce516a51631b93a6 (dns block)
  • viewblock.io
    • Triggering command: /home/REDACTED/work/starknet-foundry/starknet-foundry/target/debug/deps/sncast-ce516a51631b93a6 (dns block)
  • voyager.online
    • Triggering command: /home/REDACTED/work/starknet-foundry/starknet-foundry/target/debug/deps/sncast-ce516a51631b93a6 (dns block)
  • www.oklink.com
    • Triggering command: /home/REDACTED/work/starknet-foundry/starknet-foundry/target/debug/deps/sncast-ce516a51631b93a6 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of cptartur October 9, 2025 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change exit code when sncast returns error

3 participants