Skip to content

Accept 2xx (including 201 Created) from Registry API on publish - #1417

Open
m-rinaldi wants to merge 1 commit into
purescript:masterfrom
m-rinaldi:fix/registry-accept-201-created
Open

Accept 2xx (including 201 Created) from Registry API on publish#1417
m-rinaldi wants to merge 1 commit into
purescript:masterfrom
m-rinaldi:fix/registry-accept-201-created

Conversation

@m-rinaldi

Copy link
Copy Markdown

Problem

Running spago publish fails at the very last step even though the publish request succeeds. The registry responds with HTTP 201 and a valid job payload, but spago reports it as an error:

✓ Ready for publishing. Calling the registry..
✘ Registry did not like this and answered with status 201, got answer:
  {"jobId":"58ed1d07-6c02-4c04-8c2f-7cc4672f7355"}

The job is actually created in the registry – spago just refuses to continue polling the job logs.

Cause

In callRegistry (Registry.purs), any response whose status was not exactly 200 was treated as a failure:

Just (Right { status, text }) | status /= 200 -> ... -- error branch

The registry API distinguishes job creation from a duplicate submission by HTTP status: 201 Created for a newly created job and 200 OK for an existing/duplicate job. The registry's own client accepts both (see purescript/registry-dev, submitJob / JobSubmissionResult: "the HTTP status distinguishes whether the server created a job (201) or returned an existing duplicate (200)" – its check is response.status == 200 || response.status == 201). Both are success responses carrying the same { jobId } body, but spago only accepted 200.

Fix

Treat any 2xx status as success:

Just (Right { status, text }) | status < 200 || status >= 300 -> ... -- error branch

This correctly handles both the 201 (new job) and 200 (duplicate) cases, after which spago proceeds to poll the job logs as intended.

Testing

  • npm run format:check (purs-tidy) – all files formatted.
  • spago build – succeeds.
  • spago test -p spago -- --example "publish" – 18/18 pass (no regressions).

No new automated test is included: the existing publish tests are integration tests that stop before a live registry call, baseApi is hardcoded with no injection seam, and a faithful test would require a mock registry server (out of scope for a one-line status-range fix). The correctness is established by the registry's documented status semantics and its own client's handling (submitJob), linked above.

Checklist:

  • Added the change to the "Unreleased" section of the changelog
  • Added some example of the new feature to the README (N/A – bugfix)
  • Added a test for the contribution (if applicable) (N/A – no way to mock the registry call; see Testing)

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.

2 participants