Skip to content

Commit 315ced6

Browse files
committed
docs: add message.path field conventions to Error Handling
The path field appears in examples throughout the spec but has no prose explaining how to construct it. Add a conventions section under Error Handling covering: - RFC 9535 JSONPath, snake_case property names - Simple field references, indexed array access, filter expressions - Why filter expressions are preferred over index-based paths - Specificity rule (field-level path beats parent-level) - Create vs. Update keying difference (item.id vs line item id) Complements PR #380 which fixes the schema descriptions on the message_* types.
1 parent 7e8548d commit 315ced6

1 file changed

Lines changed: 55 additions & 3 deletions

File tree

docs/specification/checkout.md

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ platform receives messages indicating what's needed to progress.
119119
The `messages` array contains errors, warnings, and informational messages
120120
about the checkout state. `ucp.status` is the shape discriminator —
121121
`"success"` means the response carries the expected payload, `"error"`
122-
means it carries error information instead. The `severity` field on each
123-
error message prescribes the recommended action:
122+
means it carries error information instead. Each message carries a `type`,
123+
`code`, `severity`, `content`, and an optional `path` that identifies the
124+
specific field or line item the message refers to (see [The `path` Field](#the-path-field) below).
125+
The `severity` field prescribes the recommended platform action:
124126

125127
| Severity | Meaning | Platform Action |
126128
| :---------------------- | :----------------------------------------------- | :---------------------------------------------------------------- |
@@ -182,6 +184,7 @@ Businesses **SHOULD** surface such messages as early as possible, and platforms
182184
"type": "error",
183185
"code": "invalid_phone",
184186
"severity": "recoverable",
187+
"path": "$.buyer.contact.phone",
185188
"content": "Phone number format is invalid"
186189
},
187190
{
@@ -219,7 +222,11 @@ IF unrecoverable is not empty
219222
220223
IF recoverable is not empty
221224
FOR EACH error IN recoverable
222-
ATTEMPT to fix error (e.g., reformat phone number)
225+
IF error.path is present
226+
IDENTIFY the field at error.path in the request payload
227+
ATTEMPT to fix that field (e.g., reformat phone at $.buyer.contact.phone)
228+
ELSE
229+
ATTEMPT generic fix based on error.code
223230
CALL Update Checkout
224231
RETURN and re-evaluate response
225232
@@ -250,6 +257,51 @@ messages or deferring to checkout completion.
250257
Example: `out_of_stock` requires specific upfront UX, whereas
251258
`payment_required` can be handled generically at submission.
252259

260+
#### The `path` Field
261+
262+
The optional `path` field on a message anchors the error to a specific
263+
component of the response payload. Platforms use it to associate error
264+
messages with the input field or line item that caused them - for example,
265+
highlighting a specific address field in a form or flagging a specific
266+
cart line.
267+
268+
`path` **MUST** be an [RFC 9535](https://www.rfc-editor.org/rfc/rfc9535)
269+
JSONPath expression relative to the root of the UCP response object.
270+
Property names **MUST** use snake_case matching the request schema.
271+
272+
**Simple field reference:**
273+
274+
```json
275+
{ "path": "$.buyer.contact.email" }
276+
```
277+
278+
**Indexed array element:**
279+
280+
```json
281+
{ "path": "$.line_items[0].quantity" }
282+
```
283+
284+
**Filter expression (preferred when referencing a specific item by ID):**
285+
286+
```json
287+
{ "path": "$.line_items[?(@.id=='line-item-uuid')].quantity" }
288+
```
289+
290+
Filter expressions are preferred over index-based paths when the platform
291+
may reorder line items between requests.
292+
293+
**Specificity rule:** A path to a specific field (e.g.,
294+
`$.buyer.contact.email`) takes precedence over a path to its parent
295+
(e.g., `$.buyer.contact`). When multiple errors apply to the same field,
296+
each message **SHOULD** carry the most specific path applicable.
297+
298+
**Create vs. Update keying:** On `create_checkout`, line item filter
299+
expressions key on `item.id` (the catalog item identifier). On
300+
`update_checkout`, they key on the line item's own `id` (the
301+
session-scoped line item identifier assigned in the create response).
302+
303+
When `path` is omitted, the message applies to the response as a whole.
304+
253305
#### Eligibility Verification at Completion
254306

255307
Platforms provide `context.eligibility` — buyer claims about eligible benefits

0 commit comments

Comments
 (0)