Files
chadebebe/.planning/debug/resolved/items-reorder-async-transaction.md
Adriano Belisario b19a3fdf48 feat: grid layout, global claim/qty toggles, admin access link, swaddle image
- Public wishlist now renders as responsive 3-col grid instead of list
- Subtitle supports line breaks (whitespace-pre-line)
- claimingEnabled and showQuantity moved to global site settings (not per-item); toggled in admin Configurações panel; claim API enforces server-side
- Admin dashboard shows admin access link with copy button
- Settings API exposes and persists the two new boolean settings

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-03 22:52:32 +00:00

61 lines
2.4 KiB
Markdown

---
status: resolved
trigger: "Investigate why reordering items fails with 'Failed to reorder item' in the wishlist app"
created: 2026-05-03T00:00:00Z
updated: 2026-05-03T00:00:00Z
---
## Current Focus
hypothesis: confirmed — async transaction callback used with synchronous better-sqlite3 driver
test: docker logs showed exact error
expecting: fix converts async transaction to synchronous
next_action: done
## Symptoms
expected: Dragging/reordering items in admin UI saves new order
actual: "Failed to reorder item" error appears on every reorder attempt
errors: TypeError: Transaction function cannot return a promise
reproduction: Attempt to reorder any wishlist item in /admin
started: unknown
## Eliminated
- hypothesis: HTTP method mismatch
evidence: route exports POST, frontend calls POST
timestamp: 2026-05-03
- hypothesis: auth issue
evidence: error occurs inside the transaction, not at auth check
timestamp: 2026-05-03
- hypothesis: body parsing / missing newSortOrder
evidence: error occurs after body is parsed and validated
timestamp: 2026-05-03
## Evidence
- timestamp: 2026-05-03
checked: docker logs chadomartin --tail=50
found: "TypeError: Transaction function cannot return a promise" in items reorder route
implication: better-sqlite3 is synchronous; async callbacks to db.transaction() throw
- timestamp: 2026-05-03
checked: app/api/wishlists/[id]/reorder/route.ts
found: uses synchronous pattern — db.transaction((tx) => { ... .run() ... .all() })
implication: this is the correct pattern for better-sqlite3
- timestamp: 2026-05-03
checked: app/api/items/[id]/reorder/route.ts
found: uses async pattern — await db.transaction(async (tx) => { await tx.update()... })
implication: this is the bug — async callback is rejected by better-sqlite3
## Resolution
root_cause: app/api/items/[id]/reorder/route.ts used `await db.transaction(async (tx) => { ... })` — an async callback. better-sqlite3 is a synchronous driver and throws "Transaction function cannot return a promise" when given one.
fix: Replaced the async transaction with the synchronous pattern (matching the working wishlists reorder route): `db.transaction((tx) => { ... .run() ... .all() })` with no async/await inside.
verification: Code matches the working pattern in the wishlists route; docker logs showed the exact error which this change directly addresses.
files_changed:
- app/api/items/[id]/reorder/route.ts