Skip to content

Exit with status 1 when proxy mirror fails to mirror a package - #502

Open
cestercian wants to merge 1 commit into
git-pkgs:mainfrom
cestercian:fix/mirror-exit-status-on-failures
Open

cestercian wants to merge 1 commit into
git-pkgs:mainfrom
cestercian:fix/mirror-exit-status-on-failures

Conversation

@cestercian

Copy link
Copy Markdown

Fixes #500

runMirror printed N failed and the error list, then returned normally, so proxy mirror exited 0 even when every download failed. A CI step that prewarms the cache could never notice a partial mirror.

Now, after the summary and the error list are printed (same output as before), the command exits with status 1 if progress.Failed > 0. The decision is a small mirrorExitCode(progress) helper, so it's easy to test, and the DB is closed before os.Exit like the other exit paths in runMirror. A run with no failures, including one where everything was already cached, still exits 0. --dry-run is untouched.

I also added one sentence to the mirror section of the README about the exit status.

Repro before the change (offline, using an ecosystem the resolver rejects):

$ proxy mirror --storage-url file:///tmp/pxt/store --database-path /tmp/pxt/db.sqlite pkg:bogus/foo@1.0.0
Mirror complete: 0 downloaded, 0 skipped (cached), 1 failed, 0 B total

Errors:
  bogus/foo@1.0.0: resolving download URL: unsupported ecosystem: bogus
$ echo $?
0

pkg:pypi/requests@2.0.0 from #414 did the same. With this change both exit 1, and pkg:npm/lodash@4.17.21 still mirrors and exits 0.

Tests, in a new cmd/proxy/mirror_test.go:

  • TestMirrorExitCode: table test for the helper (nil, all mirrored, all cached, one failure, all failed)
  • TestMirrorExitsNonZeroWhenDownloadsFail: runs proxy mirror pkg:bogus/foo@1.0.0 in a subprocess against a temp sqlite DB and file storage, the same re-exec pattern TestServeHelpListsUpstreamEnvironmentVariables uses. It checks for exit status 1 and that the failure is still reported. No network needed.
go test ./...
go vet ./cmd/...
golangci-lint run ./cmd/proxy/...   # 0 issues

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.

proxy mirror exits 0 when downloads fail

1 participant