fix: Make apify push fail when secrets are missing instead of silently continuing, with optional flag to preserve old behavior #922
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.
Problem
The
apify push
command had problematic behavior whenactor.json
contained environment variables that reference non-existent secrets. Instead of failing with a clear error (which would be the expected behavior), it would:This could lead to actors being deployed in production without required environment variables, potentially causing runtime failures that are difficult to debug.
Solution
Modified the secret handling functions in
src/lib/secrets.ts
to throw errors instead of emitting warnings when secrets are missing:transformEnvToEnvVars()
now collects all missing secrets and throws a single comprehensive errorreplaceSecretsValue()
follows the same pattern for consistencyError Behavior
When secrets are missing, users now get a clear error message:
Impact
This change affects both:
apify push
- Now fails when trying to deploy with missing secretsapify run
- Now fails when trying to run locally with missing secretsBackward Compatibility
✅ Fully maintained - All existing functionality works exactly the same for:
@
prefix)Optional Flag for Legacy Behavior
Added
--ignore-missing-secrets
flag to bothapify push
andapify run
commands:This provides a migration path for users who need the old behavior while making the secure approach the default.
Testing
--ignore-missing-secrets
flag behaviorThis ensures users can no longer accidentally deploy actors with missing critical environment variables, while providing clear guidance on how to resolve the issue and an optional flag to preserve legacy behavior when needed.
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.