fix: handle unknown/empty task statuses without crashing

A task with status='' caused the Kanban byColumn memo to throw
TypeError: undefined is not an object (out[t.status].push).

Defensive UI: bucket unknown statuses into backlog with a console
warning. Defensive API: reject PATCHes with invalid status values
(including empty string) with a 400. Cleaned up two existing
empty-status rows in PB.
This commit is contained in:
Dave 2026-08-17 19:00:42 +02:00
parent c349998fa1
commit 19f60eba42
2 changed files with 17 additions and 1 deletions

View file

@ -55,6 +55,12 @@ export async function PATCH(req: NextRequest, { params }: { params: { id: string
// edges — drag-and-drop an "in_progress" card to "backlog" silently
// no-ops (the UI should use the explicit /cancel endpoint).
if (typeof body.status === "string") {
if (!Object.prototype.hasOwnProperty.call(STATUS_TRANSITIONS, body.status)) {
return NextResponse.json(
{ error: `invalid status: ${body.status}` },
{ status: 400 },
);
}
const current = await fetchRecord<PBRecord>(COLLECTION, params.id);
const allowed = STATUS_TRANSITIONS[current.status as string] || [];
if (!allowed.includes(body.status)) {

View file

@ -106,7 +106,17 @@ export default function KanbanBoard() {
done: [],
failed: [],
};
for (const t of filtered) out[t.status].push(t);
for (const t of filtered) {
const bucket = out[t.status as TaskStatus];
if (!bucket) {
// Unknown status — log once and put in backlog so the user
// can see it and fix it from the detail panel.
console.warn(`[Kanban] task ${t.id} has unknown status ${JSON.stringify(t.status)} — putting in backlog`);
out.backlog.push(t);
continue;
}
bucket.push(t);
}
return out;
}, [filtered]);