n8n-io/n8n · error · NotFoundError
Target user not found
Error message
Target user not found
What it means
Returned by PATCH /users/:id/role when userRepository.findOne({id,relations:['role']}) returns null — the target user does not exist. Message is the NO_USER constant ('Target user not found') from UsersController.ERROR_MESSAGES.CHANGE_ROLE. HTTP 404. Fires after the self-role and provisioning guards.
Source
Thrown at packages/cli/src/controllers/users.controller.ts:365
if (await this.provisioningService.isInstanceRoleManaged()) {
throw new ForbiddenError(
'Instance roles are managed automatically and cannot be changed manually',
);
}
const { NO_ADMIN_ON_OWNER, NO_USER, NO_OWNER_ON_OWNER, CANNOT_CHANGE_OWN_ROLE } =
UsersController.ERROR_MESSAGES.CHANGE_ROLE;
if (req.user.id === id) {
throw new ForbiddenError(CANNOT_CHANGE_OWN_ROLE);
}
const targetUser = await this.userRepository.findOne({
where: { id },
relations: ['role'],
});
if (targetUser === null) {
throw new NotFoundError(NO_USER);
}
if (
req.user.role.slug === GLOBAL_ADMIN_ROLE.slug &&
targetUser.role.slug === GLOBAL_OWNER_ROLE.slug
) {
throw new ForbiddenError(NO_ADMIN_ON_OWNER);
}
if (
req.user.role.slug === GLOBAL_OWNER_ROLE.slug &&
targetUser.role.slug === GLOBAL_OWNER_ROLE.slug
) {
throw new ForbiddenError(NO_OWNER_ON_OWNER);
}
await this.userService.changeUserRole(targetUser, payload);
View on GitHub (pinned to 5ac6606e81)
Solutions
- Verify the target user exists (GET /users/:id) before issuing the role change.
- Do not retry the same id; treat 404 as terminal.
- Refresh the admin user list and re-select the target.
Defensive patterns
Strategy: validation
Validate before calling
async function ensureTargetUserExists(id: string) {
const r = await fetch(`/rest/users/${id}`);
if (r.status === 404) throw new Error(`Target user ${id} not found; refresh the user list`);
} Try / catch
try { await fetch(`/rest/users/${id}/role`, { method: 'PATCH', body }); }
catch (e) { if (e.statusCode === 404) { /* refresh list, reselect */ } else throw e; } Prevention
- Refresh the user list before role changes.
- Do not retry the same unknown id.
- Validate the id format (UUID) before sending.
When it happens
Trigger: PATCH /users/<unknown-or-deleted-id>/role with a valid RoleChangeRequestDto; target id is not in the users table.
Common situations: Operating on a stale user list; user was deleted between page load and role change; cross-environment id mismatch.
Related errors
- User not found
- User to generate invite link for not found
- Request to delete a user failed because the user to delete w
- Request to delete a user failed because the transferee proje
- Cannot change your own global role
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/3115e29e0e07e3f7.
Report an issue: GitHub.