{"record":{"id":"739bc7fa41066be7","repo":"actualbudget/actual","slug":"new-user-not-found","errorCode":"new-user-not-found","errorMessage":"New user not found","messagePattern":"New user not found","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"packages/sync-server/src/app-admin.js","lineNumber":403,"sourceCode":"        status: 'error',\n        reason: 'invalid-file-id',\n        details: 'File not found at server',\n      });\n      return;\n    }\n\n    if (!newUserOwner.newUserId) {\n      res.status(400).send({\n        status: 'error',\n        reason: 'user-cant-be-empty',\n        details: 'Username cannot be empty',\n      });\n      return;\n    }\n\n    const newUserIdFromDb = UserService.getUserById(newUserOwner.newUserId);\n    if (newUserIdFromDb === 0) {\n      res.status(400).send({\n        status: 'error',\n        reason: 'new-user-not-found',\n        details: 'New user not found',\n      });\n      return;\n    }\n\n    UserService.updateFileOwner(newUserOwner.newUserId, newUserOwner.fileId);\n\n    res.status(200).send({ status: 'ok', data: {} });\n  },\n);\n\napp.use(errorMiddleware);\n","sourceCodeStart":385,"sourceCodeEnd":418,"githubUrl":"https://github.com/actualbudget/actual/blob/d4334cb6e6123f4d3bcea1ad6166608884c7e658/packages/sync-server/src/app-admin.js#L385-L418","documentation":"This 400 error is returned when the admin file-ownership endpoint is given a newUserId that passes the empty check but does not exist in the server database. UserService.getUserById returns 0 rows and the server responds with reason 'new-user-not-found'. The target user must be an existing account on this sync server.","triggerScenarios":"Calling the admin endpoint with newUserId set to a user id that was deleted, exists only on another server, or was mistyped.","commonSituations":"Stale user ids cached in admin tooling after the user was removed; pointing an admin script at a server where the user was never created (fresh database); id vs username confusion — passing a username where a user id is expected.","solutions":["List users on the server (admin users endpoint) and use the exact id of an existing user.","Create the user on this server first if it genuinely does not exist, then retry the ownership transfer.","Check you are not passing a username/display name where the API expects the internal user id."],"exampleFix":"// before\nawait setFileOwner({ fileId, newUserId: 'alice' }); // username, not id\n// after\nconst users = await adminListUsers();\nconst user = users.find(u => u.userName === 'alice');\nawait setFileOwner({ fileId, newUserId: user.userId });","handlingStrategy":"validation","validationCode":"const users = await adminListUsers();\nif (!users.some(u => u.userId === newUserId)) {\n  throw new Error(`User ${newUserId} not found on this server`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await setFileOwner({ fileId, newUserId });\n} catch (e) {\n  if (e.reason === 'new-user-not-found') {\n    // create the user or pick an existing id from adminListUsers()\n  }\n}","preventionTips":["Look up user ids via the admin users endpoint instead of trusting stored/remembered ids.","Distinguish clearly between usernames and internal user ids in tooling.","Re-create users after a database reset before reassigning file ownership."],"tags":["sync-server","rest-api","not-found","admin"],"backgroundTag":"resource-not-found","analyzedSha":"d4334cb6e6123f4d3bcea1ad6166608884c7e658","analyzedAt":"2026-08-29T01:02:11.213Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}