{"record":{"id":"0914ac5a439d4edd","repo":"abi/screenshot-to-code","slug":"design-system-not-found","errorCode":null,"errorMessage":"Design system not found","messagePattern":"Design system not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"backend/routes/design_systems.py","lineNumber":149,"sourceCode":"        if design_system.id != design_system_id:\n            continue\n\n        updated = design_system.model_copy(\n            update={\n                \"name\": normalize_name(request.name)\n                if request.name is not None\n                else design_system.name,\n                \"content\": request.content\n                if request.content is not None\n                else design_system.content,\n                \"updatedAt\": utc_timestamp(),\n            }\n        )\n        design_systems[index] = updated\n        write_design_systems(design_systems)\n        return updated\n\n    raise HTTPException(status_code=404, detail=\"Design system not found\")\n\n\n@router.delete(\"/api/design-systems/{design_system_id}\")\nasync def delete_design_system(design_system_id: str) -> Response:\n    design_systems = read_design_systems()\n    remaining = [\n        design_system\n        for design_system in design_systems\n        if design_system.id != design_system_id\n    ]\n\n    if len(remaining) == len(design_systems):\n        raise HTTPException(status_code=404, detail=\"Design system not found\")\n\n    write_design_systems(remaining)\n    return Response(status_code=204)\n","sourceCodeStart":131,"sourceCodeEnd":166,"githubUrl":"https://github.com/abi/screenshot-to-code/blob/d026163f586dfa8c5c10d28c36edd59a9d3b0e88/backend/routes/design_systems.py#L131-L166","documentation":"Raised by the update handler PUT /api/design-systems/{design_system_id} (404) when no stored design system has a matching id. The handler scans the in-memory list by id and falls through to this exception when the loop finds nothing — the id may be wrong, or the entry was deleted between read and write.","triggerScenarios":"PUT /api/design-systems/{id} with an id that is not in design-systems.json: stale id after a delete, typo, or a fresh data directory that no longer holds the entry.","commonSituations":"UI keeps an edit dialog open while another tab deletes the system; switched data dir / machine so the file has different ids; copied id with whitespace.","solutions":["GET /api/design-systems and use an id from the current list.","If the system is missing, create it with POST instead of PUT.","Confirm the backend points at the same SCREENSHOT_TO_CODE_DATA_DIR used when the id was issued."],"exampleFix":"# before\nrequests.put(url + f\"/api/design-systems/{ds_id}\", json={\"name\": \"new\"})  # 404\n\n# after\nids = {d[\"id\"] for d in requests.get(url + \"/api/design-systems\").json()}\nif ds_id not in ids:\n    resp = requests.post(url + \"/api/design-systems\", json=payload)\nelse:\n    resp = requests.put(url + f\"/api/design-systems/{ds_id}\", json=payload)","handlingStrategy":"validation","validationCode":"systems = requests.get(url + \"/api/design-systems\").json()\nknown_ids = {s[\"id\"] for s in systems}\nif ds_id not in known_ids:\n    ds_id = None  # create instead of update\nverb, path = ((\"PUT\", f\"/api/design-systems/{ds_id}\") if ds_id\n              else (\"POST\", \"/api/design-systems\"))","typeGuard":"def design_system_exists(ds_id: str, systems: list[dict]) -> bool:\n    return any(s.get(\"id\") == ds_id for s in systems)","tryCatchPattern":"resp = requests.put(url + f\"/api/design-systems/{ds_id}\", json=payload)\nif resp.status_code == 404:\n    resp = requests.post(url + \"/api/design-systems\", json=payload)  # upsert\nresp.raise_for_status()","preventionTips":["Refresh the systems list before editing.","Implement upsert semantics (fall back to POST on 404) when ids may be stale.","Confirm the data dir matches the one that issued the id."],"tags":["fastapi","http-404","crud","design-systems"],"backgroundTag":null,"analyzedSha":"d026163f586dfa8c5c10d28c36edd59a9d3b0e88","analyzedAt":"2026-08-14T22:02:06.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}