[w3c/browser-payment-api] PaymentRequest constructor errors should be properly annotated (#290)

In the section that details the algorithm for the Payment Request constructor, there are multiple places where a TypeError is thrown. If these errors are not annotated (_TypeError.message_ is set), it will be difficult for a developer to determine why the TypeError was thrown (as there are multiple ways it can be thrown in the constructor algorithm).

https://w3c.github.io/browser-payment-api/#paymentrequest-constructor

After chatting a bit with @rsolomakhin, he noted that Chromium does annotate the TypeErrors. The specification shouldn't make a normative requirement on what the text should be, but should provide hints via "optional messages" much like the DOM4 entry in the Dependencies section: https://w3c.github.io/browser-payment-api/#h-dependencies so that developers working across multiple browsers can depend on more or less the same TypeError annotation text.

@rsolomakhin identified the following _TypeError.message_s that can be thrown in the PaymentRequest constructor in Chromium:

https://chromium.googlesource.com/chromium/src/+/0f7bc8677b8f04c46bbbd574b98faa5a2161769a/third_party/WebKit/Source/modules/payments/PaymentRequest.cpp#166

- Item label required
- Currency amount required
- Currency code required
- Currency value required
- ShippingOption id required
- Duplicate shipping option identifiers are not allowed
- Must specify at least one payment details modifier
- Must specify at least one payment method identifier
- Duplicate payment method identifiers are not allowed
- Total amount value should be non-negative
- Must specify total
- Total amount value should be non-negative
- Must specify at least one payment method identifier
- Must specify at least one payment method identifier
- Duplicate payment method identifiers are not allowed
- Unable to parse payment method specific data
- Data should be a JSON-serializable object

I'll try to submit a PR to fix this if it's agreed that this is a good thing to include in the spec.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/browser-payment-api/issues/290

Received on Thursday, 29 September 2016 15:22:51 UTC