immich-app/immich · error · Error

User not found

Error message

User not found

What it means

NotificationAdminService.sendTestEmail fetches the user by id to address the test email; if userRepository.get returns null (no user with that id, or it is deleted), it throws a plain Error 'User not found'. This is a precondition check before SMTP verification and rendering, so it fails fast rather than building an email to nowhere.

Source

Thrown at server/src/services/notification-admin.service.ts:28

@Injectable()
export class NotificationAdminService extends BaseService {
  async create(auth: AuthDto, dto: NotificationCreateDto) {
    const item = await this.notificationRepository.create({
      userId: dto.userId,
      type: dto.type ?? NotificationType.Custom,
      level: dto.level ?? NotificationLevel.Info,
      title: dto.title,
      description: dto.description,
      data: dto.data,
    });

    return mapNotification(item);
  }

  async sendTestEmail(id: string, dto: SystemConfigSmtpDto, tempTemplate?: string) {
    const user = await this.userRepository.get(id, { withDeleted: false });
    if (!user) {
      throw new Error('User not found');
    }

    try {
      await this.emailRepository.verifySmtp(dto.transport);
    } catch (error) {
      throw new BadRequestException('Failed to verify SMTP configuration', { cause: error });
    }

    const { server } = await this.getConfig({ withCache: false });
    const { html, text } = await this.emailRepository.renderEmail({
      template: EmailTemplate.TEST_EMAIL,
      data: {
        baseUrl: getExternalDomain(server),
        displayName: user.name,
      },
      customTemplate: tempTemplate!,
    });
    const { messageId } = await this.emailRepository.sendEmail({

View on GitHub (pinned to 199723261c)

Solutions

  1. Use GET /users (admin) to find a valid user id and retry.
  2. If the user was deleted, either restore them or pick an active user.
  3. Confirm the id is a valid UUID matching an existing user record.

Example fix

// before
await adminApi.sendTestEmail('wrong-uuid', smtpDto);
// after
const users = await userApi.getAll();
await adminApi.sendTestEmail(users[0].id, smtpDto);
Defensive patterns

Strategy: validation

Validate before calling

const users = await api.userApi.getAll();
if (!users.some((u) => u.id === userId)) {
  throw new Error(`User ${userId} does not exist`);
}
await adminApi.sendTestEmail(userId, smtpDto);

Type guard

const userExists = (id: string, users: { id: string }[]) =>
  users.some((u) => u.id === id);

Try / catch

try {
  await adminApi.sendTestEmail(userId, smtpDto);
} catch (e) {
  if (/User not found/.test(String(e?.message))) {
    // refresh user list and pick a valid id
  } else throw e;
}

Prevention

When it happens

Trigger: POST to the admin test-email endpoint with an id that does not match a user row. Triggered by an admin entering/testing a non-existent user id, a deleted user, or a stale reference after user cleanup.

Common situations: Copied wrong user id; user was deleted (withDeleted:false excludes them); testing against a fresh DB with no users.

Related errors


AI-assisted analysis of immich-app/immich@199723261c (2026-08-12). Data as JSON: /api/errors/83bd7bbe719d4212. Report an issue: GitHub.