-
Notifications
You must be signed in to change notification settings - Fork 272
feat: Add first-class errors concept #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
d9df3c2 to
d5c195b
Compare
|
@richmolj Why not codify this? Thinking something like: bf70b4d It sounds like you considered something much more verbose as an alternative, but I think we can still ship something against the schemas here in a non-breaking way that prevents docs taking responsibility of communicating what certain strings mean for the code field 😄 |
d5c195b to
fa3d6cc
Compare
|
@raginpirate good call, updated! |
|
naive qq here because we are talking about the error codes in EP transport as well. How do we envision the name "first party"?
|
raginpirate
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥 🚀
My proposal for encoding this used consts just because you can have descriptions alongside consts, which I feel is really nice for documenting error codes, allowing us to move some of this context out of docs and right into the schema. |
| "$id": "https://ucp.dev/schemas/shopping/types/error_code.json", | ||
| "title": "Error Code", | ||
| "description": "Error code identifying the type of error. First-class errors have standardized semantics; freeform codes are also permitted.", | ||
| "oneOf": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work.
oneOf requires exactly one match. "out_of_stock" matches both its const AND type: string and validation will fail for any const we define here. In theory, anyOf walks around that, but it renders all the branches redundant because type: string will match everything regardless.
Suggestion:
"description": "Error code identifying the type of error. First-class errors have standardized semantics; freeform codes are also permitted.",
"type": "string",
"examples": [
"out_of_stock",
"item_unavailable",
"address_undeliverable",
"payment_failed"
]
examples is a no-op at validation time but it's a built-in annotation for tooling that matches content in the spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good catch, yes the intention was to write this as an anyOf!
Sounds like you're just disagreeing with the premise here: #147 (comment). The intention is not to actually improve static typing; a const is obviously a string, its to co-locate context about different error codes in the schema. Examples doesn't do this by default: its unclear if those examples are just random strings which obviously I can use as an error code, or if they have specific meaning for implementation.
We can solve this via comments in this file, or we can solve it via anyOf consts + fallback string, or we can choose to just let external docs deal with informing implementers they must do something special for these codes. IMO I like this solution because it nudges implementers looking at schemas in the right direction, rather than docs they may never read, but comments over examples can too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with Daniel but don't have a strong opinion. Updated to Ilya's approach since this is not a one-way door.
fa3d6cc to
c6e0bef
Compare
|
igrigorik
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 modulo wording suggestion.
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "$id": "https://ucp.dev/schemas/shopping/types/error_code.json", | ||
| "title": "Error Code", | ||
| "description": "Error code identifying the type of error. Standard errors have standardized semantics; freeform codes are also permitted.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "description": "Error code identifying the type of error. Standard errors have standardized semantics; freeform codes are also permitted.", | |
| "description": "Error code identifying the type of error. Standard errors are defined in specification (see examples), and have standardized semantics; freeform codes are permitted.", |
a2bcc13 to
1d0e963
Compare
It's helpful for Platforms to understand certain error codes and handle these scenarios with first-class treatment. Consider:
last_name_required: No problem, maps to input field so can be handled with generic form validationpayment_required: No problem, buyer hasn't reached this step yetinsufficient_stock: No problem, business can allocate what's possible and give warning message on remaining quantityOUT_OF_STOCK: Problem! Platform may want to handle this immediately with a modal (e.g.create_checkout), only show in their Cart page UX (item goes out of stock some time after adding to cart), or elsewise provide specific/appropriate UX for this critical scenario.Without this, Platforms need to understand each merchant's bespoke error code implementation. A small set of codes with first-class treatment is in the best interest of both merchant and buyer.
Given we also want merchant-defined codes, this cannot be an enum and is only defined in documentation.
This is not an exhaustive list, just a basic setup. PR reviewers: please note any other low-hanging fruit.
Type of change
Please delete options that are not relevant.
functionality to not work as expected, including removal of schema files
or fields)
Checklist