Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 10, 2025

Fix: Exit with code 1 on command errors

Commands were exiting with code 0 when encountering errors (missing arguments or exceptions during execution), breaking CI/CD workflows and shell scripts that rely on exit codes.

Changes

Error handling in ApifyCommand._run()

  • Missing required arguments now calls process.exit(1) after printing error message
  • Runtime exceptions are caught, logged, and result in process.exit(1) after telemetry completes
  • Test mode re-throws exceptions instead of exiting to allow test assertions
  • Refactored to avoid throwing in finally block (ESLint no-unsafe-finally rule)

Test updates

  • Changed error validation from checking logged messages to expecting thrown exceptions
  • Added test coverage for duplicate secret error handling
  • Removed unused lastErrorMessage variables

Example

Before:

$ apify secrets add
Error: Missing 2 required arguments: name, value
$ echo $?
0  # Wrong

After:

$ apify secrets add
Error: Missing 2 required arguments: name, value
$ echo $?
1  # Correct

The fix applies to all commands system-wide, not just secrets add.

Original prompt

This section details on the original issue you should resolve

<issue_title>Calling apify secrets add without arguments results in exit code 0</issue_title>
<issue_description>- As mentioned in the title - calling apify secrets add without arguments results in exit code 0

  • The expected result is a non-zero exit code
  • Since the command calls addSecret which throws an Error, there's a good chance that this is not properly handled for any command
    </issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 10, 2025 10:22
Co-authored-by: B4nan <615580+B4nan@users.noreply.github.com>
Co-authored-by: B4nan <615580+B4nan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix exit code for apify secrets add without arguments Fix: Exit with code 1 on command errors Nov 10, 2025
Copilot AI requested a review from B4nan November 10, 2025 10:38
Copilot finished work on behalf of B4nan November 10, 2025 10:38
@vladfrangu
Copy link
Member

@copilot please fix the linting errors and the failing tests. 👀

…bles

Co-authored-by: vladfrangu <17960496+vladfrangu@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 12, 2025

@copilot please fix the linting errors and the failing tests. 👀

Fixed the linting errors and all tests are passing. Changes in commit 38681dc:

  1. Removed throw from the finally block (no-unsafe-finally rule) by refactoring to move telemetry and error handling outside the finally block
  2. Removed unused lastErrorMessage variables from test files

All 56 tests passing ✅

Copilot AI requested a review from vladfrangu November 12, 2025 09:49
Copilot finished work on behalf of vladfrangu November 12, 2025 09:49
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.

Calling apify secrets add without arguments results in exit code 0

3 participants