Skip to content

Fix: --force exits with error when no prior deployment exists#209

Open
codxbrexx wants to merge 1 commit intometacall:masterfrom
codxbrexx:fix/force-flag-empty-repo
Open

Fix: --force exits with error when no prior deployment exists#209
codxbrexx wants to merge 1 commit intometacall:masterfrom
codxbrexx:fix/force-flag-empty-repo

Conversation

@codxbrexx
Copy link
Contributor

Closes #208

Problem

Running metacall-deploy --force on a project that has never been deployed exits with:
X Deployment Aborted because this directory is not being used by any applications.

and the deploy never starts.

The root cause: api.inspect() returns an empty array when no deployment exists. The old check if (repo) is always truthy for an empty array in JS, so the code proceeds to repo[0].prefix — which is undefined — and throws. The catch block then calls error() and exits with code 1.

The existing comment in force.ts already documents the intended behavior: if no deployment is found, --force should skip deletion and continue as a normal deploy.

Changes

src/force.ts

  • Replace if (repo) with if (repo.length > 0) to correctly detect an empty result
  • Guard repoSubscriptionDetails[0] access independently listSubscriptionsDeploys() and inspect() are separate API calls and their results may not align
  • Show an info message when skipping deletion so the user understands what's happening
  • Update the catch message to accurately describe what it covers

src/test/force.spec.ts new file

  • Three unit tests using a mock API — no credentials or network required:
    1. Empty inspect() → returns '' without throwing (regression test)
    2. Deployment + subscription found → deletes and restores args.plan
    3. Deployment found, no subscription match → deletes without crashing on repoSubscriptionDetails[0]

Testing

# unit tests only — no credentials needed
./node_modules/.bin/mocha dist/test/force.spec.js

# full local CI steps
npm run lint
npm run build

All pass. Integration tests require API credentials and are only run on push to master per the existing CI workflow.
image

'if (repo)' was always truthy for empty arrays, crashing on repo[0].
Replace with repo.length > 0 and guard repoSubscriptionDetails[0].
Add unit tests for empty, full, and mismatched cases.
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.

Bug: --force exits with "Deployment Aborted" when no existing deployment is found.

1 participant