# `data.lookup_not_email`

Code looks a record up by a field that doesn't hold an email address, and only an exact email address finds one person.

Area 15, [Personal data](/docs/personal-data.md); not declinable; the next step is usually the agent's.

## Why Jadpo refuses it

A lookup finds one person by the one thing someone is given to find them
by: the exact address of their account. Finding by any other field would
let an action find records by what they hold, past the entity's `read:`.
So `<Entity>.lookup` takes only a field built on `Email`.

## What it looks like

main.jadpo:

```jadpo
principal {
    user: {
        subject: Member.handle
    }
}

authentication {
    api_token: {}
}

policy {
    actions: {
        has_account: [Access.authenticated]
    }
}

type Handle = Text {
    max_length: 40
}

type AddressStanding = Enum {
    account_held
    no_account
}

entity Member {
    id: Uuid
    handle: Handle {
        unique: true
    }
    email: Email {
        unique: true
    }

    policy: {
        create: [Access.public]
        read: [id]
    }
}

/// Whether an address has an account.
action has_account(handle: Member.handle) -> AddressStanding {
    match Member.lookup(handle: handle) {
        none -> {
            return AddressStanding.no_account
        }
        some -> {
            return AddressStanding.account_held
        }
    }
}
```

```text
error: `Member.lookup` finds by `handle`, which isn't built on `Email`
 --> main.jadpo:43:25
   |
43 |     match Member.lookup(handle: handle) {
   |                         ^^^^^^ `Handle`
  reason: A lookup finds one person by their exact email address, the one thing about them a person is given to find them by. Any other field would let an action find records by what they hold. `Member.handle` is `Handle`.
  next: Find the `Member` by a field built on `Email`, or by its `id` with `Member.get` (agent)
  rule: data.lookup_not_email
  help: https://jadpo.dev/docs/errors/data.lookup_not_email

check failed: 1 error, 1 file
```

`(agent)` at the end of the `next:` line means your coding agent can make
the fix itself: it names the email field.

## How to fix it

**If you are finding someone by their address**, look them up by the
field that holds it, an `Email` that is `unique: true`:

```jadpo
action has_account(email: Member.email) -> AddressStanding {
    match Member.lookup(email: email) {
        none -> {
            return AddressStanding.no_account
        }
        some -> {
            return AddressStanding.account_held
        }
    }
}
```


The lookup now finds the one member with that address, or none.

**If you know the record's `id`**, read it with `Member.get(member_id)`,
which its entity's `read:` decides:

```jadpo
    var member: Member = attempt Member.get(member_id)
```


A caller then reads only what the entity's `read:` lets them.

## Related

- [Looking up one person by email](/docs/looking-up-one-person-by-email.md)
- [`data.lookup_not_unique`](/docs/errors/data.lookup_not_unique.md)
