ErrorsPersonal data · rule
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; 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:
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 } }}
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.handleisHandle. - next
- Find the
Memberby a field built onEmail, or by itsidwithMember.get(agent) - rule
- data.
lookup_ not_ email - help
- https://jadpo.
dev/docs/errors/data. lookup_ not_ email
(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:
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:
var member: Member = attempt Member.get(member_id)A caller then reads only what the entity's read: lets them.
Related
Markdown for agents: /docs/errors/data.lookup_not_email.md.Built from Jadpo's main branch at commit 9080dc3.