{"record":{"id":"b3630330bc50ee84","repo":"actualbudget/actual","slug":"cannot-find-user-to-update","errorCode":"cannot-find-user-to-update","errorMessage":"Cannot find user ${userName} to update","messagePattern":"Cannot find user (.+?) to update","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"packages/sync-server/src/app-admin.js","lineNumber":132,"sourceCode":"      reason: `${!userName ? 'user-cant-be-empty' : 'role-cant-be-empty'}`,\n      details: `${!userName ? 'Username' : 'Role'} cannot be empty`,\n    });\n    return;\n  }\n\n  const roleIdFromDb = UserService.validateRole(role);\n  if (!roleIdFromDb) {\n    res.status(400).send({\n      status: 'error',\n      reason: 'role-does-not-exists',\n      details: 'Selected role does not exist',\n    });\n    return;\n  }\n\n  const userIdInDb = UserService.getUserById(id);\n  if (!userIdInDb) {\n    res.status(400).send({\n      status: 'error',\n      reason: 'cannot-find-user-to-update',\n      details: `Cannot find user ${userName} to update`,\n    });\n    return;\n  }\n\n  UserService.updateUserWithRole(\n    userIdInDb,\n    userName,\n    displayName || null,\n    enabled ? 1 : 0,\n    role,\n  );\n\n  res.status(200).send({ status: 'ok', data: { id: userIdInDb } });\n});\n","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/actualbudget/actual/blob/d4334cb6e6123f4d3bcea1ad6166608884c7e658/packages/sync-server/src/app-admin.js#L114-L150","documentation":"PATCH /users looks up the target account with `UserService.getUserById(id)`. If no user matches the supplied `id`, the handler responds 400 with reason 'cannot-find-user-to-update' and a message naming the username from the request. The endpoint refuses to update non-existent users.","triggerScenarios":"PATCH /users (admin session) with an id that does not exist in the users table — a deleted user, a truncated/typo'd id, an id from a different server's database, or an id from a file row mistakenly used as a user id.","commonSituations":"Stale admin UI caches holding ids of users deleted elsewhere; environment mismatch (staging id used against production); copy/paste dropping characters from the uuid; migrations referencing ids that were never imported.","solutions":["Fetch the current user list via the admin API and use the exact id returned for that username.","Verify you are pointing at the same server/environment the id came from.","If the user was deleted, recreate it via POST /users instead of updating.","Log the id being sent and compare its length/format to a known-good user id (uuid)."],"exampleFix":"// before\nawait patchUser({ id: 'abc123', userName: 'jane', role: 'admin' }); // stale id\n// after\nconst users = await listUsers();\nconst jane = users.find(u => u.user_name === 'jane');\nawait patchUser({ id: jane.id, userName: 'jane', role: 'admin' });","handlingStrategy":"validation","validationCode":"const users = await listUsers(); // admin API\nconst target = users.find(u => u.user_name === userName);\nif (!target) throw new Error(`User ${userName} not found on this server`);\n// then PATCH with target.id","typeGuard":null,"tryCatchPattern":"try {\n  await patchUser({ id, userName, role });\n} catch (e) {\n  if (e.status === 400 && e.reason === 'cannot-find-user-to-update') {\n    // refresh the user list and retry with a resolved id\n    const fresh = await listUsers();\n    const u = fresh.find(x => x.user_name === userName);\n    if (u) await patchUser({ id: u.id, userName, role });\n  } else throw e;\n}","preventionTips":["Resolve ids from a fresh server list rather than cached UI state.","Never hand-type or truncate user uuids.","Confirm environment (staging vs production) before batch updates.","After deleting users, purge their ids from local caches."],"tags":["http-400","not-found","sync-server","admin-api"],"backgroundTag":"entity-not-found","analyzedSha":"d4334cb6e6123f4d3bcea1ad6166608884c7e658","analyzedAt":"2026-08-29T01:02:11.213Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}