Skip to content

sync-to-zesty: recover from 'filename already exists' on POST - #100

Merged
ardeay merged 1 commit into
stagefrom
sync-to-zesty-handle-existing-view
Sep 9, 2026
Merged

ardeay merged 1 commit into
stagefrom
sync-to-zesty-handle-existing-view

Conversation

@ardeay

@ardeay ardeay commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Per ardeay (2026-09-09 Discord, Option A on the sync-to-zesty patch).

Problem

When `sync-to-zesty.js` runs a FULL_SYNC and encounters a file on disk that isn't in `zesty.config.json` yet, it POSTs `/web/` to create the view. If the fileName is already taken in Zesty (which happens whenever someone created the view manually in the editor at some point without its ZUID landing back in the config), Zesty returns:

```
400 Bad Request: filename already exists
```

The current script surfaces that as a thrown Error, which crashes the entire run — every subsequent file in `newFiles` never gets touched. Today's example: the run choked on `adobe-experience-manager-vs-content-one.html` and never even attempted to create the 4 pages sam and kaya are waiting on.

Fix

  • `apiRequest()` attaches `.status` + `.bodyText` onto thrown Errors so callers can introspect
  • `createNew()` wraps the POST in try/catch. On `400 filename already exists`, it calls a new helper `findExistingZuidByFileName()` that GETs `/web/`, scans the list for a matching fileName, extracts the ZUID, and returns it as if the resource had just been created. The workflow's existing "Commit new-resource ZUID mappings" step then writes that ZUID back into `zesty.config.json`, so subsequent runs treat it as a normal update-in-place.
  • Any other 400 (or 401/403/etc.) still fails loud — this doesn't silently swallow real bugs

Also fixes a small `apiRequest` quirk: it used to serialize `body: undefined` as `"undefined"` via `JSON.stringify`. Now it only attaches `options.body` when there's actually a body — safer for GET/DELETE.

Test

`scripts/sync-to-zesty.test.js` — a small zero-config test that asserts the shape of the patch (recovery branch present, helper defined, body-guard in place). Run with `node scripts/sync-to-zesty.test.js`. Not wired into CI yet (would need a proper test runner) but it's easy to invoke locally.

Follow-up unblocked

Once this ships, a FULL_SYNC dispatch on stage will self-heal all ~15 currently-orphaned view records into `zesty.config.json` in a single run, eliminating the "manual ZUID hand-off after each new landing page" bottleneck that's been eating operator time all summer.

Test plan

  • Stage CI passes on merge
  • Dispatch FULL_SYNC on stage post-merge — no more crashes on filename conflicts; `zesty.config.json` gains all orphaned ZUID mappings

…xisting ZUID

Per ardeay (2026-09-09): before this patch, any file present on disk but
without a ZUID mapping in zesty.config.json triggers a POST /web/views on
stage sync. If the Zesty instance already has a view record with that
fileName (usually because it was created manually in the editor before
its ZUID made it into config), the POST fails with 400 'filename already
exists' and the whole sync crashes. Every subsequent file in newFiles is
never touched.

The patch teaches createNew() to recover from that specific 400: catch it,
GET /web/<endpoint>, find the record whose fileName matches, and continue
as if we had just created it. The workflow's writeback step then commits
the resolved ZUID into zesty.config.json so subsequent runs treat it as a
normal already-mapped resource.

Also:
- apiRequest now attaches .status and .bodyText onto the thrown Error so
  callers can introspect (previously only a string message was available)
- apiRequest no longer sends body='null' on GET/DELETE (JSON.stringify(null)
  = 'null', which some fetch implementations flag)
- Small test file exercises the shape of the patch — asserts the recovery
  branch, the helper function, and the body-on-GET guard all exist. Zero
  runtime cost since it's opt-in (node scripts/sync-to-zesty.test.js)
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

💾 Stage sync preview

New files to create (0):
none

Will add/update — differ from dev (0):
none

Unchanged, skipped: 0

196 mapped resources · zesty-sync

@ardeay
ardeay merged commit 56fbc42 into stage Sep 9, 2026
4 checks passed
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.

1 participant